Re: Order by

From: Date: Wed, 04 Aug 2004 02:32:55 +0000
Subject: Re: Order by
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-192659@lists.php.net to get a copy of this message
----- Original Message ----- From: "Karl-Heinz Schulz" <karlheinz@khschulz.com> To: <php-general@lists.php.net> Sent: Tuesday, August 03, 2004 9:19 PM Subject: [PHP] Order by > How can I use the "Order" statement for this query? > > $specs_query = mysql_query("select title, information from spec where > product=".$id); > > I tried to use > > $specs_query = mysql_query("select title, information from spec where > product=".$id order by id asc); > > But it will create the error. > > Parse error: parse error, unexpected T_STRING in /www/docs/view_product.php > on line 144 > > What am I doing wrong? > > TIA > > Karl-Heinz > > Tracking #: 28B73BEA7EBF0B4D89E64E5EA406BF5EC2EA6912 > > Hi Karl, The problem is in your formatting. > $specs_query = mysql_query("select title, information from spec where > product=".$id order by id asc); Try this instead $specs_query = mysql_query('SELECT title, information FROM spec WHERE product=' . $id . ' ORDER BY id ASC'); Note the use of single quotes (it's faster) You could have just done this with double quotes: $specs_query = mysql_query("SELECT title, information FROM spec WHERE product=$id ORDER BY id ASC"); It might also be a good idea to put single quotes around $id if it comes from user input: $specs_query = mysql_query('SELECT title, information FROM spec WHERE product=\'' . $id . '\' ORDER BY id ASC'); - OR - $specs_query = mysql_query("SELECT title, information FROM spec WHERE product='$id' ORDER BY id ASC"); Have fun! Regards, Jim Grill Web-1 Hosting http://www.web-1hosting.net ---------------------------------------------------------------------------- ---- > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.general (#192659) next »