Page 1 of 1

PHP MySQL query variable usage

Posted: Fri Dec 25, 2009 11:02 pm
by anon404

Code: Select all

$result = mysql_query("SELECT filename, ext FROM files ORDER BY '$sort'") or die(mysql_error());
The query results are not sorted. When using a static 'filename' instead of the $sort variable it sorts the result. I have tried all suggested usages for people who have had the same problem with no success. How can i fix this?

Re: PHP MySQL query variable usage

Posted: Sat Dec 26, 2009 1:07 am
by alex.barylski
Try:

Code: Select all

$result = mysql_query("SELECT filename, ext FROM files ORDER BY $sort") or die(mysql_error());
I don't think those single quotes aorund $sort are required or desired.

Cheers,
Alex

Re: PHP MySQL query variable usage

Posted: Sat Dec 26, 2009 8:14 am
by anon404
PCSpectra wrote:Try:

Code: Select all

$result = mysql_query("SELECT filename, ext FROM files ORDER BY $sort") or die(mysql_error());
I don't think those single quotes aorund $sort are required or desired.

Cheers,
Alex
Syntax error.

Edit: Solved, $sort was null... lol