Author: Sun sports
PHP also provides you with a way to handle multiple possibilities-the "if-elseif-else" structure. A typical "if-elseif-else" structure statement is as follows:
--------------------------------------------------------------------------------
If (the first condition is correct)
{
Do this!
}
Elseif (the second condition is correct)
{
Do this!
}
Elseif (the third condition is correct)
{
Do this!
}
... And so on...
Else
{
Do this!
}
--------------------------------------------------------------------------------
Here is an example of how to use it:
--------------------------------------------------------------------------------
<Html>
<Head>
<Style type = "text/css">
Td {font-family: Arial ;}
</Style>
</Head>
<Body>
<Font face = "Arial" size = "+ 2">
Amazing lucky cookie production program
</Font>
<Form method = "GET" action = "cookie. php">
<Table cellspacing = "5" cellpadding = "5" border = "0">
<Tr>
<Td align = "center">
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>
</Html>
--------------------------------------------------------------------------------
As you will see, this simple form allows you to select a day of the week. The actual processing work is done by the submitted PHP script "cookie. php.
--------------------------------------------------------------------------------
<?
If ($ day = "Monday ")
{
$ Fortune = "do not make everything simple and effective when you can find a complicated and wonderful way to do everything .";
}
Elseif ($ day = "Tuesday ")
{
$ Fortune = "is life a bridge to games? -You must use some clever tricks. ";
}
Elseif ($ day = "Wednesday ")
{
$ Fortune = "What makes people with clear minds never go crazy in this world? ";
}
Elseif ($ day = "Thursday ")
{
$ Fortune = "don't be crazy, be fun ";
}
Elseif ($ day = "Friday ")
{
$ Fortune = "just follow the times and follow the ethos. When you get an improvement, you will find that the type is a devil. ";
}
Else
{
$ Fortune = "sorry, the weekend is closed ";
}
?>
<Html>
<Head>
<Basefont face = "Arial">
</Head>
<Body>
This is you <? Echo $ day;?> Lucky words:
<Br>
<B> <? Echo $ fortune;?> </B>
</Body>
</Html>
--------------------------------------------------------------------------------
In this case, we use a control sentence to assign different Lucky words to each day.
Here is an important point worth noting-when a "if" statement in the structure is found to be true, PHP will execute the corresponding code, ignore the "if" statement in the remaining structure, immediately jump out of the "if-elseif-else" structure, and execute the rows following the entire structure.