PHP MySQL query variable usage

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
anon404
Forum Newbie
Posts: 12
Joined: Wed Dec 23, 2009 4:09 am

PHP MySQL query variable usage

Post 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?
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: PHP MySQL query variable usage

Post 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
anon404
Forum Newbie
Posts: 12
Joined: Wed Dec 23, 2009 4:09 am

Re: PHP MySQL query variable usage

Post 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
Post Reply