PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I'm going crazy! Can someone please point out how to make this code work properly... I am simply trying to display a list of all items from 1 table with checkboxes next to each item,and then pre-check some of those boxes based on values from a lookup table.
<?php //Display all cases via checkboxes and pre-check the current values
while ($selectedcase = mysql_fetch_array($selectedcases)) {
$caseid = $selectedcase['caseid'];
while ($case = mysql_fetch_array($cases)) {
$case_prodid = $case['prodid'];
$prodname = htmlspecialchars($case['prodname']);
if ($case_prodid == $caseid) { ?>
<input name="case_prodids[]" type="checkbox" value="<?php echo $case_prodid; ?>" checked> <?php echo $prodname; ?><br /><?php
}else{ ?>
<input name="case_prodids[]" type="checkbox" value="<?php echo $case_prodid; ?>"> <?php echo $prodname; ?><br /><?php
}
}
}
Currently, this is only pre-checking one box correctly (the last value in the table) even when there should be multiple boxes checked so there must be something wrong with my first WHILE or maybe just where it is???
Thank You.
Jcart | Please show of the curtosy of properly indenting your code next time, thanks
The inner while will only execute through entirely once. You will need to call mysql_data_seek() to reset the record set back to the first record, or run that loop before the $selectedcase loop storing up the information necessary to output your desired display.