Jump to content

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;

}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.