Isaiaha Posted November 21, 2010 Share Posted November 21, 2010 while ($div=mysql_fetch_array($query4, MYSQL_ASSOC)) { //$div - shows all the entries $row22=mysql_fetch_array($query2, MYSQL_ASSOC); //row22 - shows all the entries that should be checked $name= array($div['date_id']); $datess=$row22['date_id']; if (in_array($datess, $name, true)) { echo '<input type="checkbox" value="' . $div[date_id] .'" checked>' . $div[date] . '</option>'; }else{ echo '<input type="checkbox" value="' . $div[date_id] .'">' . $div[date] . '</option>'; } 1. when echo $row22 shows only the entries that should be checked - working good 2. checkboxes show checked if only the first checkbox is selected or all 3 - if a combination is selected, it is all blank. Any ideas? Thank you Quote Link to comment https://forums.phpfreaks.com/topic/219395-marking-checkboxes-as-checked-if-in_array/ Share on other sites More sharing options...
Isaiaha Posted November 21, 2010 Author Share Posted November 21, 2010 Here's more information: $query2 checks which checkboxes the user has selected wants to verify it against all the checkboxes in $query4 than mark $query2 checkboxes as checked. Thank you Quote Link to comment https://forums.phpfreaks.com/topic/219395-marking-checkboxes-as-checked-if-in_array/#findComment-1137660 Share on other sites More sharing options...
mrherman Posted November 21, 2010 Share Posted November 21, 2010 Probably has nothing to do with your problem, but the WHILE loop "seems" to be missing its closing curly brace. Quote Link to comment https://forums.phpfreaks.com/topic/219395-marking-checkboxes-as-checked-if-in_array/#findComment-1137699 Share on other sites More sharing options...
Isaiaha Posted November 22, 2010 Author Share Posted November 22, 2010 Hi Thank you - i might have missed it in the posting... this is where i'm at now which is working tons better but having a glitch described at the bottom - wondering if anyone knows? Here's the code: $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" echo '<input type="checkbox" value="' . $div[date_id] .'" "checked">' . $div[date] . '</option>'; } else { //display checkbox without being checked echo '<input type="checkbox" value="' . $div[date_id] .'">' . $div[date] . '</option>'; } //reset the pointer in $row22 back to the start mysql_data_seek($query2,0); } This is what happens: Anytime checkbox #1 is selected: displays all checkboxes as checked If checkbox #2 is selected: displays 2&3 checked If checkbox #3 is selected: displays correctly - only 3 is checked. If checkbox 2&3 selected: display correctly I hope I haven't kiboshed your code... i was trying something sort of like your code (mine was much messier) and I was having the same issue. Wondering what would make it act that way. Quote Link to comment https://forums.phpfreaks.com/topic/219395-marking-checkboxes-as-checked-if-in_array/#findComment-1137702 Share on other sites More sharing options...
Isaiaha Posted November 22, 2010 Author Share Posted November 22, 2010 Thank you - system solved $checked = false; had to be put in after the first while! Quote Link to comment https://forums.phpfreaks.com/topic/219395-marking-checkboxes-as-checked-if-in_array/#findComment-1137703 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.