PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
nickman013
Forum Regular
Posts: 764 Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York
Post
by nickman013 » Sun Apr 02, 2006 1:31 pm
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!
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Sun Apr 02, 2006 1:45 pm
Code: Select all
<?php
$sql4 = "SELECT * FROM `comments` WHERE who =".$row['Number']." ORDER BY who DESC";
?>
Will this do it?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Apr 02, 2006 1:45 pm
concatenate some more..
Code: Select all
$sql4 = "SELECT * FROM `comments` WHERE who =" . $row['Number'] . "ORDER BY `foo` DESC";
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Sun Apr 02, 2006 1:48 pm
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.
nickman013
Forum Regular
Posts: 764 Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York
Post
by nickman013 » Sun Apr 02, 2006 1:49 pm
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
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Sun Apr 02, 2006 2:04 pm
Post your query again, exactly as it is being called.
nickman013
Forum Regular
Posts: 764 Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York
Post
by nickman013 » Sun Apr 02, 2006 2:14 pm
Code: Select all
$sql4 = "SELECT * FROM `comments` WHERE who =" . $row['Number'] . "ORDER BY `id` DESC";
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Apr 02, 2006 2:28 pm
might need a space before the ORDER bit.
nickman013
Forum Regular
Posts: 764 Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York
Post
by nickman013 » Sun Apr 02, 2006 2:30 pm
Thank you both!!!!
Ambush Commander
DevNet Master
Posts: 3698 Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US
Post
by Ambush Commander » Sun Apr 02, 2006 2:45 pm
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 ";
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Sun Apr 02, 2006 3:45 pm
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