Re: [PHP] $_GET, expressions and conditional statements

2004-03-11 Thread Jason Wong
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
*/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] $_GET, expressions and conditional statements

2004-03-11 Thread Neil Freeman
How about this - untested by the way:

$order = ASC;

if (isset($_GET[ORDER]))
{
$value = $_GET[ORDER];
if (($value == ASC) || ($value == DESC))
{
$order = $value;
}
else if ($value == RAND)
{
$order = RAND();
}
}
$SPORDER = $order;



I.A. Gray wrote:

***
This Email Has Been Virus Swept
***
Hi everyone,

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.
Here is part of the script:

?php

if (!isset($_GET['ORDER'])) { // Checks if the 'ORDER' 
variable from the
URL is set.  If it is NOT set the following happens...
$SPORDER = ASC; // The variable $SPORDER is given 
the value ASC, since
ASC (Ascending Order) is the default value.
}
else { // The following happens if the 'ORDER' 
variable IS set...
$SPORDER = $_GET['ORDER']; // The variable 
$SPORDER is given the value
of the variable 'ORDER' taken from the URL.
if  ( (($SPORDER !== ASC)  ($SPORDER !== DESC)) 
 ($SPORDER !==
RAND)) { // If the variable $SPORDER does NOT have the value of either
ASC (Ascending), DESC (Descending) or RAND (Random) then the following
happens...
$SPORDER == ASC;  // The variable 
$SPORDER is given the default
value ASC
}
else { // If the variable $SPORDER DOES have the value 
of either ASC,
DESC or RAND then the following happens...
if ($SPORDER == RAND) { // If $SPORDER has the 
following of RAND
(Random Order) then...
$SPORDER == RAND(); // $SPORDER is 
given the value RAND() which
is the correct value for submission to the MYSQL query.
}
}
	} // End of the Conditional Statements regarding the ORDER variable.

?

I think the problem part could be: if  ( (($SPORDER !== ASC)  ($SPORDER
!== DESC))  ($SPORDER !== RAND))
I am trying to say if $SPORDER does not equal ASC, DESC or RAND then
do the following.  There maybe other problems in my code as well that are
not making this work.  I would be grateful if you could shed some light on
it!
Best wishes,
Ian Gray
--
--
 www.curvedvision.com
--
This communication is confidential to the intended recipient(s). If you are not that person you are not permitted to make use of the information and you are requested to notify the sender immediately of its receipt then destroy the copy in your possession. Any views or opinions expressed are those of the originator and may not represent those of Advanced System Architectures Ltd.

*** This Email Has Been Virus Checked ***

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


RE: [PHP] $_GET, expressions and conditional statements

2004-03-11 Thread Ford, Mike [LSS]
 -Original Message-
 From: Jason Wong [mailto:[EMAIL PROTECTED] 
 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: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php