4WebHelp
 FAQ  •  Search  •  User Groups  •  Forum Admins  •  Smilies List  •  Statistics  •  Rules   •  Login   •  Register
Toggle Navigation Menu

 If statement
Post New TopicReply to Topic
View Previous Topic Print this topic View Next Topic
Author Message
Kdawg
Senior WebHelper
Senior WebHelper


Joined: 21 Apr 2003
Posts: 153

PostPosted: Sat Apr 26, 2003 12:52 am (20 years, 12 months ago) Reply with QuoteBack to Top

How is a PHP if statment formated, like if $game = North Royaltin then $game = North_Royaltin?
OfflineView User's ProfileFind all posts by KdawgSend Personal Message
Daniel
Team Member



Joined: 06 Jan 2002
Posts: 2564

PostPosted: Sat Apr 26, 2003 7:29 am (20 years, 12 months ago) Reply with QuoteBack to Top

A correct if statement would be:

Code:
if ($game = 'North Royaltin') {
  function_to_run();
}


Although the code you gave doesn't make sense, since it doesn't do anything Smile

________________________________
Image
OfflineView User's ProfileFind all posts by DanielSend Personal Message
adam
Forum Moderator & Developer



Joined: 26 Jul 2002
Posts: 704
Location: UK

PostPosted: Sat Apr 26, 2003 9:32 am (20 years, 12 months ago) Reply with QuoteBack to Top

that should be:
Code:
if ($game == 'North Royaltin') {
  function_to_run();
}


note the double equals

________________________________
It's turtles all the way down...
OfflineView User's ProfileFind all posts by adamSend Personal MessageVisit Poster's Website
Daniel
Team Member



Joined: 06 Jan 2002
Posts: 2564

PostPosted: Sat Apr 26, 2003 12:11 pm (20 years, 12 months ago) Reply with QuoteBack to Top

Sorry - teach me to check out these forums when I have only 5 minutes on the PC Very Happy

________________________________
Image
OfflineView User's ProfileFind all posts by DanielSend Personal Message
drathbun
WebHelper
WebHelper


Joined: 01 Mar 2003
Posts: 69
Location: Texas

PostPosted: Sat Apr 26, 2003 10:17 pm (20 years, 12 months ago) Reply with QuoteBack to Top

You'll also often see this, if there is just a single statement to be evaluated:
Code:
$some_var = ($testvar == 'some value') ? $true_result : $false_result;

This is identical (at least from a functional standpoint) to:
Code:
if ($testvar == 'some value')
{
     $some_var = $true_result
}
else
{
     $some_var = $false_result
}

It just does it all on one line. Cool I use this quite frequently, actually.

Dave

________________________________
Dave
Photography Site :: Query Tools Forum :: Weekend Fun
OfflineView User's ProfileFind all posts by drathbunSend Personal MessageVisit Poster's Website
Iyonix
WebHelper
WebHelper


Joined: 12 Nov 2002
Posts: 82
Location: Yarm, England

PostPosted: Sun Apr 27, 2003 9:04 am (20 years, 12 months ago) Reply with QuoteBack to Top

Kdawg wrote:
How is a PHP if statment formated, like if $game = North Royaltin then $game = North_Royaltin?


You want this:

Code:

if($game=="North Royaltin") $game="North_Royaltin";

________________________________
Iyonix
OfflineView User's ProfileFind all posts by IyonixSend Personal Message
adam
Forum Moderator & Developer



Joined: 26 Jul 2002
Posts: 704
Location: UK

PostPosted: Sun Apr 27, 2003 9:33 am (20 years, 12 months ago) Reply with QuoteBack to Top

lol...so many different ways of writing the same thing.

________________________________
It's turtles all the way down...
OfflineView User's ProfileFind all posts by adamSend Personal MessageVisit Poster's Website
Kdawg
Senior WebHelper
Senior WebHelper


Joined: 21 Apr 2003
Posts: 153

PostPosted: Tue May 13, 2003 8:57 pm (20 years, 11 months ago) Reply with QuoteBack to Top

How do I use or in an if statment like
if ($number == '1' or $number == '2') {
function_to_run();
}
OfflineView User's ProfileFind all posts by KdawgSend Personal Message
SfCommand
Senior WebHelper
Senior WebHelper


Joined: 10 Nov 2002
Posts: 143
Location: UK

PostPosted: Tue May 13, 2003 9:04 pm (20 years, 11 months ago) Reply with QuoteBack to Top

Try
Code:
if (($number == '1') or ($number == '2')) {
  function_to_run();
}

________________________________
Miguel

http://community.34sp.com
http://www.miguel.me.uk | http://www.sfcommand.co.uk | http://www.ssdg.org.uk
OfflineView User's ProfileFind all posts by SfCommandSend Personal MessageVisit Poster's Website
Kdawg
Senior WebHelper
Senior WebHelper


Joined: 21 Apr 2003
Posts: 153

PostPosted: Tue May 13, 2003 9:06 pm (20 years, 11 months ago) Reply with QuoteBack to Top

It worked the way I had it, lol. I guess I should test it before I ask.
OfflineView User's ProfileFind all posts by KdawgSend Personal Message
jayant
Team Member



Joined: 07 Jan 2002
Posts: 262
Location: New Delhi, India

PostPosted: Thu May 15, 2003 3:00 pm (20 years, 11 months ago) Reply with QuoteBack to Top

Code:
if (($number == '1') || ($number == '2')) {
  function_to_run();
}
is better

________________________________
Jayant Kumar
Member of the 4WebHelp Team
Nibble Guru - Computing Queries Demystified
GZip/ Page Compression Test
OfflineView User's ProfileFind all posts by jayantSend Personal MessageVisit Poster's WebsiteYahoo MessengerMSN Messenger
Display posts from previous:      
Post New TopicReply to Topic
View Previous Topic Print this topic View Next Topic


 Jump to:   




You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot edit your posts in this forum.
You cannot delete your posts in this forum.
You cannot vote in polls in this forum.


Page generation time: 0.293589 seconds :: 18 queries executed :: All Times are GMT
Powered by phpBB 2.0 © 2001, 2002 phpBB Group :: Based on an FI Theme