kyleldi Posted April 14, 2009 Share Posted April 14, 2009 I've got a page on this site I'm working on that has a drop down menu that varies based on what is in the Format column. How would I set up my IF statement? So far I'm running into snags. This is what I've come up with so far, but I think I'm a little off track. Can anyone help throw me in the right direction? There is only a possibility of four different options in that column, so I don't really need an else statement for if it doesn't meet either of the previous four criteria. <?php if ($row_rs_itemdetail['format']==Format1) { echo 'Format 1 Dropdown'; if ($row_rs_itemdetail['format']==Format2) { echo 'Format 2 Dropdown'; if ($row_rs_itemdetail['format']==Format3) { echo 'Format 3 Dropdown'; if ($row_rs_itemdetail['format']==Format4) { echo 'Format 4 Dropdown'; }?> Thank You, Link to comment https://forums.phpfreaks.com/topic/154092-solved-conditional-if-statement/ Share on other sites More sharing options...
kodosai Posted April 14, 2009 Share Posted April 14, 2009 This might be a little more to standards and produce less overhead, but you do have the right idea. You might want to also look in to case/switch function in PHP as some people find that format easier to follow. **Also added in closing curly braces for the if/elseif/else segments (that was probably a typo in the original) <?php if ($row_rs_itemdetail['format']==Format1) { echo 'Format 1 Dropdown'; { elseif ($row_rs_itemdetail['format']==Format2) { echo 'Format 2 Dropdown'; } elseif ($row_rs_itemdetail['format']==Format3) { echo 'Format 3 Dropdown'; } else($row_rs_itemdetail['format']==Format4) { echo 'Format 4 Dropdown'; }?> Link to comment https://forums.phpfreaks.com/topic/154092-solved-conditional-if-statement/#findComment-810008 Share on other sites More sharing options...
Mchl Posted April 14, 2009 Share Posted April 14, 2009 And how about switch? switch($row_rs_itemdetail['format']) { case "Format1": echo 'Format 1 Dropdown'; break; case "Format2": echo 'Format 3 Dropdown'; break; case "Format3": echo 'Format 3 Dropdown'; break; case "Format4": echo 'Format 4 Dropdown'; break; } Link to comment https://forums.phpfreaks.com/topic/154092-solved-conditional-if-statement/#findComment-810010 Share on other sites More sharing options...
kyleldi Posted April 14, 2009 Author Share Posted April 14, 2009 Switch seems like a great idea... I plugged it into my page and I keep getting an unexpected $end error, pointing to the ?> bracket on the last line of my page. Any ideas? Link to comment https://forums.phpfreaks.com/topic/154092-solved-conditional-if-statement/#findComment-810028 Share on other sites More sharing options...
Mchl Posted April 14, 2009 Share Posted April 14, 2009 You have unpaired { somewhere (most likely) Link to comment https://forums.phpfreaks.com/topic/154092-solved-conditional-if-statement/#findComment-810030 Share on other sites More sharing options...
kyleldi Posted April 14, 2009 Author Share Posted April 14, 2009 Forgot an ending } Thanks so much! Link to comment https://forums.phpfreaks.com/topic/154092-solved-conditional-if-statement/#findComment-810031 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.