Forum Moderators: coopster

Message Too Old, No Replies

SELECT and ORDER BY ignores the ORDER BY

mySQL SELECT ORDER BY

         

Gruessle

7:37 am on Feb 26, 2005 (gmt 0)

10+ Year Member




It does not give me an error but it orders by id not cYear as I ask it to.

Am I doing something wrong because this looks to me like a bug.

$p_edu = mysql_query("SELECT * FROM profile_edu WHERE (cid = '$uid') ORDER BY cYear ASC") or die ("Could not read data because ".mysql_error());

Nutter

1:49 pm on Feb 26, 2005 (gmt 0)

10+ Year Member



Just a guess, the single quotes around $uid may be confusing it. Try breaking out of the quotes before using the variables. So - WHERE (id='".$uid."') ORDER BY... -

Is cYear how the field is capitalized in your database? That's a mistake I made all the time. I finally just started using all lower case field names.

- Ryan

Gruessle

7:41 pm on Feb 26, 2005 (gmt 0)

10+ Year Member



That was it, I changed it to following:

SELECT * FROM profile_edu WHERE (cid = $uid) ORDER BY cYear DESC

What is wrong about using caps in mysql?

Nutter

7:51 pm on Feb 26, 2005 (gmt 0)

10+ Year Member



Nothing's wrong with using caps. Just a personal decision. I tend to confuse myself with mixed case. But, my first thought when I saw your code was that maybe the field was cyear in the database.

The way I do my SQL code is to do fieldnames all lower case and the commands all upper. So - SELECT field1, field2 FROM tablename WHERE field='whatever' ORDER BY field ASC - That way it's easy for me to separate the commands from the fields in my mind.