Page 1 of 1
Sort By descending
Posted: Sun Apr 02, 2006 1:31 pm
by nickman013
Hello,
I need help with my query. I know how to sort stuff by descending order, but I cant seem to get it into my query so it will work.
This is my query.
Code: Select all
$sql4 = "SELECT * FROM `comments` WHERE who =".$row['Number'];
I just need to add ORDER BY descending, but I cant figure it out because of the concated stuff.
Thanks!
Posted: Sun Apr 02, 2006 1:45 pm
by RobertGonzalez
Code: Select all
<?php
$sql4 = "SELECT * FROM `comments` WHERE who =".$row['Number']." ORDER BY who DESC";
?>
Will this do it?
Posted: Sun Apr 02, 2006 1:45 pm
by feyd
concatenate some more..
Code: Select all
$sql4 = "SELECT * FROM `comments` WHERE who =" . $row['Number'] . "ORDER BY `foo` DESC";
Posted: Sun Apr 02, 2006 1:48 pm
by RobertGonzalez
Batman's trusty sidekick, Robin wrote:Holy fidgety fingers Batman, did I post before Feyd.
Stephen Hawking wrote:I do believe the space-time continuum, as we know it this day, may be forever imbalanced.
Posted: Sun Apr 02, 2006 1:49 pm
by nickman013
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'BY `id` DESC' at line 1
Hmmm
Posted: Sun Apr 02, 2006 2:04 pm
by RobertGonzalez
Post your query again, exactly as it is being called.
Posted: Sun Apr 02, 2006 2:14 pm
by nickman013
Code: Select all
$sql4 = "SELECT * FROM `comments` WHERE who =" . $row['Number'] . "ORDER BY `id` DESC";
Posted: Sun Apr 02, 2006 2:28 pm
by feyd
might need a space before the ORDER bit.
Posted: Sun Apr 02, 2006 2:30 pm
by nickman013
Thank you both!!!!
Posted: Sun Apr 02, 2006 2:45 pm
by Ambush Commander
A general good habit to get into is to always put a space before and after SQL snippets. So... it becomes:
Code: Select all
$sql4 = " SELECT * FROM `comments` WHERE who = " . $row['Number'] . " ORDER BY `id` DESC ";
Posted: Sun Apr 02, 2006 3:45 pm
by John Cartwright
This is a bit off topic, but it looks like you are using nested query calls --
bad bad bad.
If you would like more help on this, make a post in the Database forums
