RE: [PHP] $_GET, expressions and conditional statements
| From: | Ford, Mike [LSS] | Date: | Thu, 11 Mar 2004 19:38:21 +0000 |
| Subject: | RE: [PHP] $_GET, expressions and conditional statements | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-180209@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Jason Wong [mailto:php-general@gremlins.biz]
> Sent: 11 March 2004 14:19
>
> On Thursday 11 March 2004 21:15, I.A. Gray wrote:
>
> > What I want the
> > script to do is set $SPORDER to this value. If
> $_GET['ORDER'] is not
> > set then it gets the default value (ASC), if this is any other than
> > ASC, DESC or RAND (ie. someone has messed with the variables in the
> > URL) then it also gets the default (ASC). Finally if
> $_GET['ORDER'] is
> > set to RAND then I want $SPORDER to equal RAND() so that I
> can use the
> > value in the SQL query.
>
> Try something like:
>
> if (isset($_GET['ORDER'])) {
> switch ($_GET['ORDER']) {
> case 'ASC' :
> case 'DESC' :
> case 'RAND' :
> $SPORDER = $_GET['ORDER'];
> break;
> default :
> $SPORDER = 'ASC';
> }}
> else {
> $SPORDER = 'ASC';
> }
Or even:
switch (@$_GET['ORDER']):
case 'ASC':
case 'DESC':
$SPORDER = $_GET['ORDER'];
break;
case 'RAND':
$SPORDER = 'RAND()';
break;
default :
$SPORDER = 'ASC';
endswitch;
(which, I think, also gives the requested result for 'RAND').
Cheers!
Mike
---------------------------------------------------------------------
Mike Ford, Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services, JG125, James
Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6
3QS, United Kingdom
Email: m.ford@leedsmet.ac.uk
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211