RE: [PHP] Ordering a query

From: Date: Sat, 08 Sep 2001 07:37:18 +0000
Subject: RE: [PHP] Ordering a query
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-66516@lists.php.net to get a copy of this message
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: nate@1feehosting.com [mailto:nate@1feehosting.com] Sent: Friday, September 07, 2001 10:05 PM To: php-general@lists.php.net 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

« previous php.general (#66516) next »