You are here: Re: Switch isset and $_get « PHP Programming Language « IT news, forums, messages
Re: Switch isset and $_get

Posted by Pedro Graca on 10/22/06 17:17

wouter wrote:
> hey hi.....
>
> I wanna make a switch wich does this:
>
> if pagid is set do A,
> if catid is set do B,
> if projectid is set do C,
> else do D.
>
> So i was thinking something like this:
>
> switch()
> {
> case isset ($_GET['pagid']):
> {
> echo "pagid= set";
> }
> break;
> case isset ($_GET['catid']):
> {
> echo "catid= set";
> }
> break;
> case isset ($_GET['projectid']):
> {
> echo "projectid= set";
> }
> break;
> default:
> {
> echo "nothing set";
> }
> }
>
>
> wich works great in my mind but not on my server....

You need something to switch on
switch ($SOMETHING)
^^^^^^^^^^

The case expressions *must* all be different. In your example, as
isset() returns either `true` or `false` at least two of them will
be equal.

PHP will then compare the $SOMETHING to the case expressions and
continue the script execution from the case expression that matches.
If there are two or more matches, how will PHP know from which match to
start?

> Anybody here know how to do this in a way wich does work??

with if()s

if (isset($_GET['pagid'])) { echo "pagid= set"; }
elseif (isset($_GET['catid'])) { echo "catid= set"; }
elseif (isset($_GET['projectid'])) { echo "projectid= set"; }
else { echo "nothing set"; }

You might want to think about what happens if there's more than one of
those $_GET parameters set ...

Happy Coding :)

--
File not found: (R)esume, (R)etry, (R)erun, (R)eturn, (R)eboot

I don't check the dodgeit address (very often).
If you *really* need to mail me,
use the address in the Reply-To header.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация