Re: $_GET, expressions and conditional statements

From: Date: Thu, 11 Mar 2004 14:19:24 +0000
Subject: Re: $_GET, expressions and conditional statements
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-180145@lists.php.net to get a copy of this message
On Thursday 11 March 2004 21:15, I.A. Gray wrote: > I know this is probably really simple, but I am not very good at > expressions and conditional statements. I am wanting to show a list from a > MYSQL database. I am using the URL to store the variables that control the > output. The variable $ORDER can be set to ASC (Ascending), DESC > (Descending and RAND (Random). 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'; } -- Jason Wong -> Gremlins Associates -> www.gremlins.biz Open Source Software Systems Integrators * Web Design & Hosting * Internet & Intranet Applications Development * ------------------------------------------ Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general ------------------------------------------ /* When a student asks for a second time if you have read his book report, he did not read the book. -- Rominger's Rules for Teachers n1 */

« previous php.general (#180145) next »