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
wesnoel
Forum Commoner
Posts: 58 Joined: Fri Sep 05, 2003 11:53 am
Post
by wesnoel » Mon Jan 12, 2004 4:39 pm
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!
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 » Mon Jan 12, 2004 4:43 pm
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 » Mon Jan 12, 2004 4:47 pm
OK I'll give that try. Thanks! I'll keep you posted.
Wes/
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Mon Jan 12, 2004 4:58 pm
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){
case $qty < 50 :
....
break;
case $qty > 49 :
....
break;
}
scorphus
Forum Regular
Posts: 589 Joined: Fri May 09, 2003 11:53 pm
Location: Belo Horizonte, Brazil
Contact:
Post
by scorphus » Mon Jan 12, 2004 5:02 pm
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 » Mon Jan 12, 2004 6:03 pm
Thanks guys I got it working. You all rock!