Switch case and greater than

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
wesnoel
Forum Commoner
Posts: 58
Joined: Fri Sep 05, 2003 11:53 am

Switch case and greater than

Post 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?
penguinboy
Forum Contributor
Posts: 171
Joined: Thu Nov 07, 2002 11:25 am

Post 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;
?>
wesnoel
Forum Commoner
Posts: 58
Joined: Fri Sep 05, 2003 11:53 am

Post by wesnoel »

OK I'll give that try. Thanks! I'll keep you posted.

Wes/ :)
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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;
User avatar
scorphus
Forum Regular
Posts: 589
Joined: Fri May 09, 2003 11:53 pm
Location: Belo Horizonte, Brazil
Contact:

Post by scorphus »

Or maybe just

Code: Select all

<?php
$address = ($qty > 49) ? $email2 : $email1;
?>
wesnoel
Forum Commoner
Posts: 58
Joined: Fri Sep 05, 2003 11:53 am

Post by wesnoel »

Thanks guys I got it working. You all rock! :D
Post Reply