Forum Moderators: coopster

Message Too Old, No Replies

Multiple if/then with PHP

         

johnnydequino

10:12 pm on Sep 1, 2004 (gmt 0)

10+ Year Member



<? if ($row->rebateprice <= 0.01)
{$row->rebateprice = "($row->rebateprice)";
$cost = "not just free, you make:"; $color = '#CC0000'; } else {$cost = "Your cost:"; $color = '#000000'; }
print "$cost &nbsp;<font color='$color'>$row->rebateprice</font>";?></a></strong>

The above script I put together with comments from this thread and it works great! Only problem is, I can have a scenerio where based on rounding <> .05 I would like it to read "FREE!" instead of the current wording. One more if statement. I have tried several scenerios and could not get it to work correctly. Any advice?

Thanks for all your help!

jd

Knowles

10:54 pm on Sep 1, 2004 (gmt 0)

10+ Year Member



Have you tried elseif?
if ($row->rebateprice <= 0.01)
{$row->rebateprice = "($row->rebateprice)";
$cost = "not just free, you make:"; $color = '#CC0000'; }
elseif ($row->rebateprice => 0.01 && $row->rebateprice <= 0.05){
echo "something here";
}else {$cost = "Your cost:"; $color = '#000000'; }

This is untested so it may not work but just a thought.

johnnydequino

2:26 am on Sep 2, 2004 (gmt 0)

10+ Year Member



hmmm - gave it a try and came up with this:

<? if ($row->rebateprice <= 0.01)
{$row->rebateprice = "($row->rebateprice)";
$cost = "not just free, you make:"; $color = '#CC0000'; }
elseif ($row->rebateprice => 0.01 && $row->rebateprice <= 0.05)
{$row->rebateprice = "($row->rebateprice)";
$cost = "Free! Your cost:"; $color = '#CC0000'; }
else {$cost = "Your cost:"; $color = '#000000'; }
print "$cost &nbsp;<font color='$color'>$row->rebateprice</font>";?>

With this error: Parse error: parse error, unexpected T_DOUBLE_ARROW

johnnydequino

4:38 pm on Sep 2, 2004 (gmt 0)

10+ Year Member



I got it. Here are the results that work if anyone wants to apply these to their site. Thanks for all your help -

<? if ($row->rebateprice < 0.00)
{$row->rebateprice = "($row->rebateprice)";
print "not just free, you make: <font color='#CC0000'>$row->rebateprice</font>"; }
elseif ($row->rebateprice == 0.00)
{$row->rebateprice = "($row->rebateprice)";
print "Free! Your cost: <font color='#CC0000'>$row->rebateprice</font>"; }
elseif ($row->rebateprice > 0.00)
{$row->rebateprice = "$row->rebateprice";
print "Your cost: <font color='#000000'>$row->rebateprice</font>"; }?>

jd