ipwnzphp Posted July 5, 2011 Share Posted July 5, 2011 I have this script i am coding and it just repeats the checkboxes over and over... i need it to only show the checkboxes for each amentie once and show checked if it is in the database... <? $result = mysql_query("SELECT * FROM amenties ORDER BY id DESC"); while ($row = mysql_fetch_array($result)) { foreach ($explode_amen as $aman) { if($aman == $row['id']) { $picked = "checked"; } else { $picked = ""; } ?> <div style="float:left; width:210px;"><input name="amen[]" type="checkbox" id="amen[]" style="width:25px;" value="<?=$row['id']?>" <?=$picked?> /><?=$row['amen_name']?></div> <? } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/241104-help-stop-foreach-looping/ Share on other sites More sharing options...
btherl Posted July 5, 2011 Share Posted July 5, 2011 Instead of the foreach loop you can use this: if (in_array($row['id'], $explode_amen)) { # Yes, it's checked } else { # No it's not checked } That should fix the problem. The problem is that your checkbox display code is inside the foreach loop. Quote Link to comment https://forums.phpfreaks.com/topic/241104-help-stop-foreach-looping/#findComment-1238404 Share on other sites More sharing options...
ipwnzphp Posted July 5, 2011 Author Share Posted July 5, 2011 Thanks! worked like a champ!! Quote Link to comment https://forums.phpfreaks.com/topic/241104-help-stop-foreach-looping/#findComment-1238406 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.