[RESOLVED] to add "desc" into mysql_query but it dont take affect
hi
I am newbee to this category, my problem is;
I have mysql_query that work fine so far, now I want to add "desc" into mysql_query but it dont take affect, the result just as it was without "desc".
i know "desc" can make it in decsending order say 1 to 9, then with "desc" it become 9 to 1
my query is this
$sql = mysql_query("SELECT * FROM comments WHERE tutorialid='$tutid' ORDER BY tutorialid DESC LIMIT $from, $max_results")or die(mysql_error();
thanks for advice, your suggestion is very much appreciated
:ehh::D
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();
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
Re: to add "desc" into mysql_query but it dont take affect
i am using php 5.2.5 mysql 5.0.45
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.
Re: to add "desc" into mysql_query but it dont take affect
Your first code is fine,I made a mistake.
Quote:
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.
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.
Re: to add "desc" into mysql_query but it dont take affect
yes , I should use commentid as indexing, it work. thanks.