Jump to content

[SOLVED] Conditional IF statement


kyleldi

Recommended Posts

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

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';
}?>

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;

}

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.