Username:
Password:
FileMaker 9 & PHP Foundations Tutorials

PHP Flow Control / Selection with "IF" pt. 2

Subtitles of the Movie

Now, just as in FileMaker, I can add some PHP code that results if the value is false by using the else statement. The code you want to execute after your else statement must be encapsulated in curly braces also. Here we'll say the result was equal to false. Make sure to close our curly bracket and refresh our browser. Now, if we wanted to do another comparison afterwards, just as in FileMaker, we have the elseif statement. The elseif statement is all one word and we must supply another condition inside our open and close parentheses. Here we'll say elseif X is equal to, again using three equal signs to compare the value and the type, string 20, then we'll say X is equal to the string. And I'll escape my quotation marks so they output to the browser 20. To escape we use the backslash. Then I'll say else. I don't know what X is. Sounds good to me. Let's output that to the browser and see what we get. X is equal to the string 20. So as you can see, our comparative evaluation is coming up true when we compare for string. One other thing to know about using if statements in PHP is that you can check for a value on a variable that has never been declared or assigned a value. Let's go back to a basic check against the value of 20 for the variable X. And we'll just use a double equal sign comparative value. We won't be comparing for type. And let's go ahead and remove our assignment for the variable X. And we'll place a little else statement that says the result was false. And let's refresh our browser and see what PHP does. Two things to note here: one is that PHP did notice that the variable X has not been assigned or been used for a value. The second thing to note is that it continued on with the if selection statement. In other words, the variable was undefined, therefore PHP entered into the else block of code and outputted that the result was false. This ability to be able to check for values on variables that haven't been declared yet is very helpful in programming your web pages. But in order to be able to do that, you will want to make sure that you turn your display errors to off or otherwise you'll get this error notice every time a variable is checked but has not been declared yet. You can do this in your PHP ini file or by using the ini set statement, which we've discussed earlier in other lessons. This concludes our lesson on using PHP's if selection statement.

Tutorial Information

Course: FileMaker 9 & PHP Foundations
Author: Lance Hallberg
SKU: 33786
ISBN: 1-933736-99-2
Release Date: 2007-08-22
Duration: 9.5 hrs / 107 lessons
Work Files: Yes
Captions: For Online University members only
Compatibility: Vista/XP/2000, OS X, Linux
QuickTime 7, Flash 8

VTC Sign up & Benefits

  • Unlimited Access
  • 81,350 Video Tutorials (20,800 free)
  • Video Available as Flash or QuickTime
  • Over 782 Courses
  • $30 for One Month Access
  • Multi-User Discounts Available