Page 1 of 1

Switch case and greater than

Posted: Mon Jan 12, 2004 4:39 pm
by wesnoel
Ok I have a qty field in my form and based on that I need to send and email to some one. It the $qty is 50 or greater I need to send to $email2 if $qty is less that 50 I need to send to $email1

This is what I have...

Code: Select all

<?php


switch($qty){ 
     case "<49": $address="$email2"; break;  
     default: $address="$email1"; 
} 


?>
It does not work! :cry:

I know nothing about using greater than less than with switch. So if anyone could help?

Posted: Mon Jan 12, 2004 4:43 pm
by penguinboy
I don't believe you can do something like that with a switch.
Why not just use an if else statment?

Code: Select all

<?php
If($qty>49)
    $address = $email2;
else
    $address = $email1;
?>

Posted: Mon Jan 12, 2004 4:47 pm
by wesnoel
OK I'll give that try. Thanks! I'll keep you posted.

Wes/ :)

Posted: Mon Jan 12, 2004 4:58 pm
by markl999
The if/else is 'better' in this case, but just a note to point out you can do such stuff in a switch if you wanted to :

Code: Select all

switch($qty)&#123;
    case $qty < 50 :
        ....
        break;
    case $qty > 49 :
        ....
        break;
&#125;

Posted: Mon Jan 12, 2004 5:02 pm
by scorphus
Or maybe just

Code: Select all

<?php
$address = ($qty > 49) ? $email2 : $email1;
?>

Posted: Mon Jan 12, 2004 6:03 pm
by wesnoel
Thanks guys I got it working. You all rock! :D