|
-
Jul 2nd, 2009, 03:08 AM
#1
Thread Starter
Fanatic Member
-
Jul 2nd, 2009, 03:22 AM
#2
Hyperactive Member
Re: to add "desc" into mysql_query but it dont take affect
I think your ORDER BY... DESC should come at the very end...
Code:
$sql = mysql_query("SELECT * FROM comments WHERE tutorialid='$tutid' LIMIT $from, $max_results ORDER BY tutorialid DESC")or die(mysql_error();
-
Jul 2nd, 2009, 03:34 AM
#3
Thread Starter
Fanatic Member
Re: to add "desc" into mysql_query but it dont take affect
BlackRiver,
Thanks for your help
when I put order by... at the end it is an error like this
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 'ORDER BY tutorialid DESC' at line 1
Code:
$sql = mysql_query("SELECT * FROM comments WHERE tutorialid='$tutid' LIMIT $from, $max_results ORDER BY tutorialid DESC")or die(mysql_error();
Regards,
cesin
-
Jul 2nd, 2009, 03:42 AM
#4
Thread Starter
Fanatic Member
Re: to add "desc" into mysql_query but it dont take affect
i am using php 5.2.5 mysql 5.0.45
-
Jul 2nd, 2009, 04:46 AM
#5
Re: to add "desc" into mysql_query but it dont take affect
you should be sorting by "commentid" or something, rather than tutorialid. tutorialid is the ID of the tutorial, and you're specifically selecting only one tutorialid ($tutid). I don't know what your table looks like, so I can't really be any more specific than that.
-
Jul 2nd, 2009, 04:51 AM
#6
Hyperactive Member
Re: to add "desc" into mysql_query but it dont take affect
Your first code is fine,I made a mistake.
MySQL pays no attention to the DESC in the ORDER BY if you order by the primary key and also include a simple equals where condition on an indexed column.
A note has been added to the 5.1.22 and 5.0.48 changelogs:
When sorting rows in an INNODB table using a primary key, where the sort was on the the
primary key column and the DESC operator was applied, the rows would be incorrectly
sorted. if you included a simple WHERE field = value clause in the query.
-
Jul 2nd, 2009, 04:57 AM
#7
Junior Member
Re: to add "desc" into mysql_query but it dont take affect
Why are you using a string datatype for numeric values if you want to sort them ?
And you are trying to sort a list of values that are the same
SELECT * FROM comments WHERE tutorialid='$tutid' ORDER BY tutorialid
so if $tutid = 5 you get only records with tutorialid = 5 and sort those fives.
-
Jul 3rd, 2009, 03:03 AM
#8
Thread Starter
Fanatic Member
Re: to add "desc" into mysql_query but it dont take affect
yes , I should use commentid as indexing, it work. thanks.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|