Re: select case **
| From: | David Robley | Date: | Tue, 26 Sep 2000 01:56:21 +0000 |
| Subject: | Re: select case ** | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-17481@lists.php.net to get a copy of this message | ||
On Tue, 26 Sep 2000, Curtis Cole wrote:
> Thanks,
>
> all of the above code is in one file called selectcase.php, the first time
> the page loads i should just see the form. the form should send the value of
> action so that one case statement is excuted and the form is displayed
> again. why is every case statment being executed along with the form when
> the page first loads.
>
> Curtis
>
>
> <?
> select ($action)
> {
> case 1:
> ?>
> <b>action is 1</b>
> a couple more lines of html
> <u>test</u>
> <?
> case 2:
> ?>
> <b> action is 2</b>
> some more lines of html
> <u>test 2</u>
> <?
> }
> ?>
>
> <?end select?>
>
> <form action="selectcase.php" method="get">
> <select name="action">
> <option>1</option>
> <option>2</option>
> <option>3</option>
> </select>
>
> <input type="Submit" name="s1" value="submit">
> </form>
You need a break; at the end of each case to stop execution from falling
through to the next case. Thus -
<?
select ($action)
{
case 1:
?>
<b>action is 1</b>
a couple more lines of html
<u>test</u>
<?
break;
case 2:
blah blah etc
--
David Robley | WEBMASTER & Mail List Admin
RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/
AusEinet | http://auseinet.flinders.edu.au/
Flinders University, ADELAIDE, SOUTH AUSTRALIA