View Single Post
  #12 (permalink)  
Old 03-13-2009, 07:40 AM
grace55 grace55 is offline
Administrator
Site Admin
 
Join Date: Jun 2008
Posts: 342
Default A journey leads to php....

The IF statement

The IF statement in PHP is very similar to using IF in real life. Like IF you don’t set your alarm clock, then you’ll be late to work in the morning. IF (and it’s friend ELSE) are known as “conditionals”.

First off, let’s look at how PHP compares values for conditionals. You’ll see “operators” in any IF statement:

• == Equal to
• != Not equal to
• < Less than
• > Greater than
• <= Less than or equal to
• >= Greater than or equal to


So, a valid IF statement could be illustrated as follows:

<?php
if ($variable == "some value") {
echo "Correct";}
?>


Expanding on IF with ELSE

You’ll most likely want to use IF with ELSE. ELSE gives you the option of doing something ELSE with your PHP script if IF doesn’t calculate one way or another. For example, you can have your site display something IF a condition is met (like a password was correct...see below!) or something ELSE if not. (Like a redirect if the password is not!)

Code example...

<?php
$five = “5”;
if ($five == “5”) {
echo "You are correct";
} else {
echo "You are incorrect";
}
?>
__________________
Christian Prayer Forum
Reply With Quote