sajan Posted October 7, 2007 Share Posted October 7, 2007 Hi I need to have a menu editing program.So i retrieve multiple menu item from database and display each item along with a check box each,so that i have multiple check boxes. But the problem is when try to display already checked values as checked in check box.sometimes i have more than one values (eg:menu1,menu2) tested against each menu for checked status.for that i tried to use foreach($menu_items as $key=>$val){ if($val['menu_item'] == for($i=0;$i<$count($alreadyCheckedMenu);$i++){$alreadyCheckedMenu[$i]}) { echo'checked'; }} But it seems to be not working.Anyone of u have any idea abt it? Link to comment Share on other sites More sharing options...
Synook Posted October 7, 2007 Share Posted October 7, 2007 Umm... don't think you can have logic blocks nested like that...what about foreach($menu_items as $key=>$val) { foreach($alreadyCheckedMenu as $current) { if($val['menu_item'] == $current) { echo'checked'; } }} Link to comment Share on other sites More sharing options...
justsomeguy Posted October 7, 2007 Share Posted October 7, 2007 A for statement does not return a value. You are comparing the menu item value with a value from a for statement, but for doesn't return anything. You need to put the if statement inside the for loop to do the testing. $checked = false;for ($i = 0; $i < count($alreadyCheckedMenu); $i++){ if ($val['menu_item'] == $alreadyCheckedMenu[$i]) $checked = true;}if ($checked) echo 'checked'; Link to comment Share on other sites More sharing options...
sajan Posted October 8, 2007 Author Share Posted October 8, 2007 Thanks for all.With slight change both examples are working fine . Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.