Download Document 7760007

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Transcript
Control Structures
you bookmark a search results page on AltaVista, you can use that bookmark to
perform the same search again later, because the search terms are contained in
the URL.
Sometimes, you want access to a variable without having to worry about whether
it was sent as part of the query string or a form post. In cases like these, the
special $_REQUEST3 array comes in handy. It contains all the variables that appear
in both $_GET and $_POST. With this variable, we can modify welcome4.php one
more time so that it can receive the first and last names of the user from either
source (welcome5.php):
<?php
$firstname = $_REQUEST['firstname'];
$lastname = $_REQUEST['lastname'];
echo( "Welcome to my Website, $firstname $lastname!" );
?>
That covers the basics of using forms to produce rudimentary user interaction
with PHP. I'll cover more advanced issues and techniques in later examples.
Control Structures
All the examples of PHP code that we've seen so far have been either simple, onestatement scripts that output a string of text to the Web page, or have been series
of statements that were to be executed one after the other in order. If you've ever
written programs in any other languages (be they JavaScript, C, or BASIC) you
already know that practical programs are rarely so simple.
PHP, just like any other programming language, provides facilities that allow us
to affect the flow of control in a script. That is, the language contains special
statements that permit you to deviate from the one-after-another execution order
that has dominated our examples so far. Such statements are called control
structures. Don't get it? Don't worry! A few examples will illustrate perfectly.
The most basic, and most often-used, control structure is the if-else statement.
Here's what it looks like:
if ( condition ) {
// Statement(s) to be executed if
// condition is true.
} else {
3
$_REQUEST is not available in versions of PHP prior to PHP 4.1.
59
Document related concepts

Object-relational impedance mismatch wikipedia, lookup

Microsoft SQL Server wikipedia, lookup

Clusterpoint wikipedia, lookup

Open Database Connectivity wikipedia, lookup

Relational model wikipedia, lookup

Database model wikipedia, lookup