Jump to content

Can we use IF this way ?


sajan

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...