PHP4 Practical Application (5)

Source: Internet
Author: User
PHP also provides you with a "IF-ELSEIF-ELSE" structure that handles a variety of possible ways. A typical "IF-ELSEIF-ELSE" structure statement looks like this:

--------------------------------------------------------------------------------
if (the first condition is correct)
{

Do this!
}
ElseIf (second correct condition)
{

Do this!
}
ElseIf (third condition correct)
{

Do this!
}
... Wait a minute...
Else
{

Do this!
}
--------------------------------------------------------------------------------
Here is an example of how to use this:

--------------------------------------------------------------------------------
< html>
< head>
< style type= "Text/css" >
td {Font-family:arial;}
</style>

< body>

< font face= "Arial" size= "+2" >
Amazing Fortune Cookie Production program
</FONT>

< form method= "get" action= "cookie.php" >
< table cellspacing= "5" cellpadding= "5" border= "0" >

< tr>
< TD align= "Center" >
Please select a date
</td>
< TD align= "right" >
< select Name= "Day" >
< option value= "Monday" >monday
< option value= "Tuesday" >tuesday
< option value= "Wednesday" >wednesday
< option value= "Thursday" >thursday
< option value= "Friday" >friday
< option value= "Saturday" >saturday
< option value= "Sunday" >sunday
</select>
</td>
</tr>

< tr>
< tr>
< TD colspan= "2" align= "Center" >
< input type= "submit" value= "click me!" >
</td>
</tr>

</table>
</form>
</body>

--------------------------------------------------------------------------------
You will see that this simple form allows you to choose a day of the week. The real processing work is done by submitting the PHP script "cookie.php".

--------------------------------------------------------------------------------
<?

if ($day = = "Monday")
{
$fortune = "Do not make it simple and effective when you can find a complex and wonderful way to make everything work."
}
ElseIf ($day = = "Tuesday")
{
$fortune = "Life is the bridge of the game?"-you must have some kind of cunning. ";
}
ElseIf ($day = = "Wednesday")
{
$fortune = "What makes the sane person live in this world and never go mad?" ";
}
ElseIf ($day = = "Thursday")
{
$fortune = "Do not be crazy, be interesting";
}
ElseIf ($day = = "Friday")
{
$fortune = "Just follow the times, follow the ethos, and when you get promoted you will find that the type is a demon." ";
}
Else
{
$fortune = "Sorry, closed on weekends";
}

?>

< html>
< head>
< Basefont face= "Arial" >

< body>
Is this you <? Echo $day;?> 's lucky words:
< br>
< b><? echo $fortune;?></b>

</body>
--------------------------------------------------------------------------------
In this case, we use control sentences to assign different lucky words to each day.

One important point to note here-when an "if" statement in a struct is found to be true, PHP executes the code, ignores the "if" statement in the remaining structure, and immediately jumps out of the "IF-ELSEIF-ELSE" structure and executes the line behind the entire structure.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.