0

Hi everyone,

I have a problem getting this code to work properly. What I need is to create a update form where the Admin user manages what menu items the different user levels will have access to by ticking or untickking the check boxes. I need the check boxes to be populated by a query result.

This code works if I use the WHERE function in the query to only select a single line of data from the database, but as soon as I do a query of the complete table it only cheacks the first line and populates the entire table with the same sequence of ticks.

If anyone can assist me with this it would be greatly appreciated.

And if possible, I need to be able to populate text fields in a form by selecting data from a dropdown list and on select it must populate the other fields by running multiple queries on multiple tables. (If possiblle - How)

<h3>Access Level Management</h3>
<fieldset>
<br />
<h3>Menu 1</h3>

<?php 
$query2="SELECT * FROM menu_1";
$result2 = mysql_query ($query2); 

?>

<?php


while($row = mysql_fetch_array($result2))  { 
$f1=$row['item'];
$f2=$row['level9']; 
if ($f2==1){
	$fc2=checked;
}

$f3=$row['level8']; 
if ($f3==1){
	$fc3=checked;
}

$f4=$row['level7']; 
if ($f4==1){
	$fc4=checked;
}

$f5=$row['level6'];
if ($f5==1){
	$fc5=checked;
}

$f6=$row['level5'];
if ($f6==1){
	$fc6=checked;
}

$f7=$row['level4'];
if ($f7==1){
	$fc7=checked;
}

$f8=$row['level3'];
if ($f8==1){
	$fc8=checked;
}

$f9=$row['level2'];
if ($f9==1){
	$fc9=checked;
}

$f10=$row['level1'];
if ($f10==1){
	$fc10=checked;
} 
?>
<table border="0" cellspacing="0" cellpadding="5" align="center" >
<tr>
<th></th>
<th>Level9</th>
<th>Level8</th>
<th>Level7</th>
<th>Level6</th>
<th>Level5</th>
<th>Level4</th>
<th>Level3</th>
<th>Level2</th>
<th>Level1</th>
</tr>
<tr align="center">
<td><?php echo $f1; ?></td>
<td><?php echo $f2; ?> </td>
<td><?php echo $f3; ?> </td>
<td><?php echo $f4; ?> </td>
<td><?php echo $f5; ?> </td>
<td><?php echo $f6; ?> </td>
<td><?php echo $f7; ?> </td>
<td><?php echo $f8; ?> </td>
<td><?php echo $f9; ?> </td>
<td><?php echo $f10; ?> </td>
</tr>

<tr align="center">
<td><?php echo $f1; ?></td>
<td><input type="checkbox" name="checkbox1" <?php echo $fc2; ?> /></td>
<td><input type="checkbox" name="checkbox2" <?php echo $fc3; ?> /></td>
<td><input type="checkbox" name="checkbox3" <?php echo $fc4; ?> /></td>
<td><input type="checkbox" name="checkbox4" <?php echo $fc5; ?> /></td>
<td><input type="checkbox" name="checkbox5" <?php echo $fc6; ?> /></td>
<td><input type="checkbox" name="checkbox6" <?php echo $fc7; ?> /></td>
<td><input type="checkbox" name="checkbox7" <?php echo $fc8; ?> /></td>
<td><input type="checkbox" name="checkbox8" <?php echo $fc9; ?> /></td>
<td><input type="checkbox" name="checkbox9" <?php echo $fc10; ?> /></td>
</tr>

<?php
}
}
?>

</table>
<br />
<input name="menu1_submit" VALUE="Apply Changes" type="submit"   />
</fieldset>

I still need to write the code to actualy update the table data. At this stage I would first like to get the fields auto populated with the data that is in the table. So ignore the Submit button for now.

Thank you

Max

1
Contributor
1
Reply
3
Views
7 Years
Discussion Span
Last Post by trilithon
0

I have solved the problem regarding the checkboxes with the following code:

<h3>Access Level Management</h3>
<fieldset>
<br />
<h3>Menu 1</h3>

<?php 
$query2="SELECT * FROM menu_1";
$result2 = mysql_query ($query2); 

?>
<table border="0" cellspacing="0" cellpadding="5" align="center" >
<tr>
<th></th>
<th>Level9</th>
<th>Level8</th>
<th>Level7</th>
<th>Level6</th>
<th>Level5</th>
<th>Level4</th>
<th>Level3</th>
<th>Level2</th>
<th>Level1</th>
</tr>

<?php


while($row = mysql_fetch_array($result2))  { 
$f1=$row['item'];
$f2=$row['level9']; 
if ($f2==1){
	$fc2[$f1]=checked;
}

$f3=$row['level8']; 
if ($f3==1){
	$fc3[$f1]=checked;
}

$f4=$row['level7']; 
if ($f4==1){
	$fc4[$f1]=checked;
}

$f5=$row['level6'];
if ($f5==1){
	$fc5[$f1]=checked;
}

$f6=$row['level5'];
if ($f6==1){
	$fc6[$f1]=checked;
}

$f7=$row['level4'];
if ($f7==1){
	$fc7[$f1]=checked;
}

$f8=$row['level3'];
if ($f8==1){
	$fc8[$f1]=checked;
}

$f9=$row['level2'];
if ($f9==1){
	$fc9[$f1]=checked;
}

$f10=$row['level1'];
if ($f10==1){
	$fc10[$f1]=checked;
} 
?>


<tr align="center">
<td><?php echo $f1; ?></td>
<td><input type="checkbox" name="checkbox1" <?php echo $fc2[$f1]; ?> /></td>
<td><input type="checkbox" name="checkbox2" <?php echo $fc3[$f1]; ?> /></td>
<td><input type="checkbox" name="checkbox3" <?php echo $fc4[$f1]; ?> /></td>
<td><input type="checkbox" name="checkbox4" <?php echo $fc5[$f1]; ?> /></td>
<td><input type="checkbox" name="checkbox5" <?php echo $fc6[$f1]; ?> /></td>
<td><input type="checkbox" name="checkbox6" <?php echo $fc7[$f1]; ?> /></td>
<td><input type="checkbox" name="checkbox7" <?php echo $fc8[$f1]; ?> /></td>
<td><input type="checkbox" name="checkbox8" <?php echo $fc9[$f1]; ?> /></td>
<td><input type="checkbox" name="checkbox9" <?php echo $fc10[$f1]; ?> /></td>
</tr>

<?php
}
}
?>

</table>
<br />
<input name="menu1_submit" VALUE="Apply Changes" type="submit"   />
</fieldset>

I just added the Item fild as a refference in the ($fc) vairiable to reflect ($fc[$f1]) Now the code works fine.


If any body has a solution with regards to the Dropdown box issue listed above, please help.


Regards,

Max

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.