Jump to content

Problem with if and else if statement


jaxdevil

Recommended Posts

I am trying to display one thing if a customer has paid and is tax exempt, something else if they paid and are not tax exempt, and something else all together if they have not paid. Here is what I am trying now, but it always displays 'error' , like it is not finding either of the other statements. Here is the code I am using....

 

if($row['paid'] == "yes" && $row['exempt'] == "1")
{echo "" .$sum2;}
else if ($row['paid'] == "yes" && $row['exempt'] == "0")
{echo "" .$sum4;}
else if ($row['paid']=="no")
{echo "UNPAID";}
else
{echo "error";}

 

Anyone see where I am going wrong?

Link to comment
Share on other sites

Try restructuring your "if" block:

<?php
if ($row['paid'] == 'yes')
    if ($row['exempt'] == '1')
        echo $sum2;
    if ($row['exempt'] == '0')
        echo $sum4;
elseif ($row['paid'] == 'no')
    echo 'UNPAID';
else
    echo 'error';
?>

or use a "switch" block:

<?php
switch ($row['paid']) {
   case 'yes':
        if ($row['exempt'] == '1')
            echo $sum2;
        if ($row['exempt'] == '0')
            echo $sum4;
        break;
   case 'no':
        echo 'UNPAID';
        break;
   default:
        echo 'error';
}?>

 

Ken

 

Link to comment
Share on other sites

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.