You could insert a ternary operation...
($order?$order:"defaultfield")
Is the same as:
if($order)
echo $order;
else
echo "defaultfield";
...
$result = mysql_query("SELECT
articles.title,vote.votes,vote.total,articles.date,staff.firstname,artic
les.content,articles.id FROM staff,articles,vote WHERE articles.authorid
= staff.id AND articles.id = vote.item ORDER BY ".
($order?$order:"defaultfield") ." DESC",$db);
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Friday, September 07, 2001 10:05 PM
To: [EMAIL PROTECTED]
Subject: [PHP] Ordering a query
I use the following code to order the results of the query by the
variable $order.
$result = mysql_query("SELECT
articles.title,vote.votes,vote.total,articles.date,staff.firstname,artic
les.content,articles.id FROM staff,articles,vote WHERE articles.authorid
= staff.id AND articles.id = vote.item ORDER BY `$order` DESC",$db);
I assign the variable a value according to my url,
http://www.mysite.com/file.php?order=something
My question is. Is there a way of assigning the $order variable a
default value? Like if they hit http://www.mysite.com/file.php without
the order=something can I tell the script to assign $order a default
value?
Thanks,
Nate
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]