![]() |
if condition in foreach loop - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: if condition in foreach loop (/showthread.php?tid=16896) |
if condition in foreach loop - El Forum - 03-19-2009 [eluser]runrun[/eluser] Hi, I am trying set default value for a select menu in the site's user profile section. In detail, I need to load the date of birth of user to a select menu, this happens when user view their profile, and this profile is editable. controller: Code: //get the date of birth of user from database view: Code: <?php foreach($Rchoices as $Rkey=>$Rchoice):?> I put the if condition in the third parameter of set_select. I get error "unexpected T_IF". if condition in foreach loop - El Forum - 03-19-2009 [eluser]pistolPete[/eluser] Try this: Code: <option value ="<?=$Rkey?>" <?=set_select('region', $Rkey, ($Rkey == $row->date) )?>><?=$Rchoice?></option> if condition in foreach loop - El Forum - 03-19-2009 [eluser]runrun[/eluser] I think I third parameter has to be "TRUE", in order to make that option default selected if condition in foreach loop - El Forum - 03-19-2009 [eluser]Armchair Samurai[/eluser] Code: <option value ="<?=$Rkey;?>" <?=set_select('region', $Rkey, $Rkey == $row->date ? TRUE : FALSE);?>><?=$Rchoice;?></option> if condition in foreach loop - El Forum - 03-19-2009 [eluser]runrun[/eluser] @pistolPete: sorry, that really works,I mistakenly put the $Rkey==$row->date in the "month" option, LOL. @Armchair Samurai: thanks man. |