So in your while loop you get a row from query 4 and a row from query 2.
Then you put the date_id from the query 4 row in an array with 1 element (the date_id).
Then you put the date_id from the query 2 row in a variable.
Then you check if that variable is present in the array with 1 element.
I don’t know what those queries did, and I’m not sure what you’re trying to do with this code, but why don’t you just compare the two date_id’s, instead of putting 1 in an array that contains only that 1 date_id?
When i do this it only shows one checkbox and doesn’t loop through. If I remove the second while statement, i get all the checkboxes but the system doesn’t seem to know which ones are checked - eventhough if I echo them, it does…
That is the wierdest thing - when I echo date_id - it is always correct / i tried your suggestion for mysql_num_rows and that was also correct.
The program acts correct if I choose the first of the 3 checkboxes… or all 3. However, if the middle, or last 2 are selected, or first and third - none are selected.
Thank you for your expertize… your code is showing a checked checkbox for each item in $query2 however it’s not showing all the checkboxes with only those selected.
if you validate using the w3c validator the ouputed html your php script generates I think you will find some invalid code which could be the cause of the names not being displayed, assuming you have checked that the records returned from the database for each query are in fact correct.
I’m now working on the assumption you want all the checkboxes displayed and the checkboxes that are in $query2 should be set to checked by default.
$checked = false;
while ($div=mysql_fetch_assoc($query4)) { //$query4 contains all the checkboxes
while($row22=mysql_fetch_assoc($query2)) { //query2 contains the checked checkboxes
if($div['date_id'] == $row22['date_id']) {
$checked = true;
}
}
//display the checkbox
if($checked) {
//display checkbox with checked="checked"
} else {
//display checkbox without being checked
}
//reset the pointer in $row22 back to the start
mysql_data_seek($row22,0);
}
ooops I made a couple of errors :headbang:,one of which you picked up with mysq_data_seek().
the other is I haven’t reset $checked at the beigining of each outer while lopp iteration
put $checked = false inside the outer while loop
while ($div=mysql_fetch_assoc($query4)) { //$query4 contains all the checkboxes
[COLOR=red]$checked = false;[/COLOR]
while($row22=mysql_fetch_assoc($query2)) { //query2 contains the checked checkboxes