Page 1 of 1
If and IFELSE
Posted: Thu Jun 10, 2004 12:34 pm
by mr-punkstar
Well the thing is, this script isnt working!
Is there away i can do this in a different way!?
I have heard of cases in ASP, i was wondering if there was anything like that for PHP!?
Code: Select all
<?php
if(!$bouncer == "")
{
$type = "bouncers";
$wage = "500";
$signon = .$wage. * 2;
}
else if(!$accountants == "")
{
$type = "accountants";
$wage = "200";
$signon = .$wage. * 2;
}
else if(!$bar == "")
{
$type = "bar";
$wage = "150";
$signon = .$wage. * 2;
}
else
{
$type = "dancers";
$wage = "350";
$signon = $wage * 2;
}
?>
Thanks,
Nick
Posted: Thu Jun 10, 2004 1:48 pm
by Illusionist
[php_man]switch()[/php_man] i think is what you're looking for. But i don't think that is going to work for you with what your trying to do. Try changing those !$var == "" to !empty($var)
Posted: Thu Jun 10, 2004 2:40 pm
by mr-punkstar
no i can see switch doing what i want!
lol
unless someone knows how I can do that the $var's have been take from statments like $_POST['bouncer'], so is there anyway I can stuff everything sent by the form into a variable, and then use a case to sort itout!?
Cheers,
nick
Posted: Thu Jun 10, 2004 3:03 pm
by dull1554
the code you have might not work cause super globals may be off on your system
Posted: Thu Jun 10, 2004 3:27 pm
by mr-punkstar
ive used them before
i have sessions aswell, and they all work fine.
Posted: Thu Jun 10, 2004 3:28 pm
by mr-punkstar
can i set all of the post items as a single variable or summat, and then use a switch to question it?
Posted: Thu Jun 10, 2004 4:36 pm
by Illusionist
did you try what i said?
Posted: Fri Jun 11, 2004 4:04 am
by Sycor
If you're still having trouble, try this...
Code: Select all
<?php
if (!empty($bouncer))
{
$type = "bouncers";
$wage = 500;
$signon = $wage * 2;
}
elseif (!empty($accountants))
{
$type = "accountants";
$wage = 200;
$signon = $wage * 2;
}
elseif (!empty($bar))
{
$type = "bar";
$wage = 150;
$signon = $wage * 2;
}
else
{
$type = "dancers";
$wage = 350;
$signon = $wage * 2;
}
?>
Posted: Fri Jun 11, 2004 12:25 pm
by mr-punkstar
Illusionist wrote:did you try what i said?
the switch?
No i could see how it would work in my position?
Posted: Fri Jun 11, 2004 1:34 pm
by Illusionist
No, i said to try this:
Sycor wrote:
If you're still having trouble, try this...
Code: Select all
<?php
if (!empty($bouncer))
{
$type = "bouncers";
$wage = 500;
$signon = $wage * 2;
}
elseif (!empty($accountants))
{
$type = "accountants";
$wage = 200;
$signon = $wage * 2;
}
elseif (!empty($bar))
{
$type = "bar";
$wage = 150;
$signon = $wage * 2;
}
else
{
$type = "dancers";
$wage = 350;
$signon = $wage * 2;
}
?>
Posted: Fri Jun 11, 2004 3:48 pm
by mr-punkstar
oh sorry, yeah I did, and it stil comes up with the final value!!
Posted: Fri Jun 11, 2004 3:52 pm
by patrikG
the bouncer get's a lot of money
