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
https://forums.phpfreaks.com/topic/76084-problem-with-if-and-else-if-statement/
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

 

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.