If and IFELSE

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
mr-punkstar
Forum Newbie
Posts: 19
Joined: Mon May 31, 2004 1:12 pm

If and IFELSE

Post 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
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post 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)
mr-punkstar
Forum Newbie
Posts: 19
Joined: Mon May 31, 2004 1:12 pm

Post 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
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post by dull1554 »

the code you have might not work cause super globals may be off on your system
mr-punkstar
Forum Newbie
Posts: 19
Joined: Mon May 31, 2004 1:12 pm

Post by mr-punkstar »

ive used them before

i have sessions aswell, and they all work fine.
mr-punkstar
Forum Newbie
Posts: 19
Joined: Mon May 31, 2004 1:12 pm

Post 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?
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

did you try what i said?
Sycor
Forum Newbie
Posts: 8
Joined: Fri Jun 11, 2004 3:54 am

Post 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; 
}

?>
mr-punkstar
Forum Newbie
Posts: 19
Joined: Mon May 31, 2004 1:12 pm

Post by mr-punkstar »

Illusionist wrote:did you try what i said?
the switch?

No i could see how it would work in my position?
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post 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;
}

?>
mr-punkstar
Forum Newbie
Posts: 19
Joined: Mon May 31, 2004 1:12 pm

Post by mr-punkstar »

oh sorry, yeah I did, and it stil comes up with the final value!!
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

the bouncer get's a lot of money ;)
Post Reply