Jump to content


Photo

varible using if statement


  • Please log in to reply
3 replies to this topic

#1 CanMan2004

CanMan2004
  • Members
  • PipPipPip
  • Advanced Member
  • 254 posts

Posted 18 September 2006 - 01:28 PM

Hi

I want to change my varible, the current code I use is

$name = "Dave Lawson";
print $name;

I want to put a if statment into the above, the if statement I want to use looks like

if ($hisname >= '1') { print " and "; } else { print "s"; };

I tried to do

$name = "Dave Lawson" if ($hisname >= '1') { print 's and '; } else { print 's'; };
print $name;

But that brought nothing but errors.

Can anyone help?

Thanks in advance

Dave

#2 Hepp

Hepp
  • Members
  • PipPipPip
  • Advanced Member
  • 33 posts

Posted 18 September 2006 - 01:37 PM

Try this:

$name = "Dave Lawson";

if ($hisname >= '1') 
{ 

print 's and '; 

} 
else 
{ 

print 's'; 

}

print $name;


#3 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 18 September 2006 - 01:41 PM

Assuming that $hisname is greater than or equal to one, the code you've just posted will print...

s and Dave Lawson

Probably not quite what you want...

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#4 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 18 September 2006 - 01:45 PM

If $hisname is not defined then it won't even do that.

Wild guess here but I think you are tryign to differentiate between one name or more and add and if its more than one....

If that is the case then you would have to explode $name and count the number of elements - but then someone might put a middle name in.

have a little think and come back with what you are trying to detect and maybe we can help a bit more.
follow me on twitter @PHPsycho




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users