DESC and AC

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

Post Reply
Qaid
Forum Commoner
Posts: 33
Joined: Wed Feb 15, 2006 12:04 pm

DESC and AC

Post by Qaid »

Hi,

When i use the function: ORDER BY id DESC

My post will be like this...
1, 2, 21, 22, etc, 3, ,31, 32, etc, 4, 5 ,6 ,7 ,8.....

Why that?

Thanks :)
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post by Grim... »

Looks like you have your ID in a TEXT field rather than an INT field.
Qaid
Forum Commoner
Posts: 33
Joined: Wed Feb 15, 2006 12:04 pm

Post by Qaid »

Looks like your right :D
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

The fix..

Code: Select all

SELECT CAST(id AS UNSIGNED) AS reorderval FROM table ORDER BY reorderval DESC
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Why not alter the table? If they're going to be numbers, there's no reason to keep them stored as textual data. The existing values will be converted to integers upon altering the table.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

feyd wrote:Why not alter the table?
Coz then I couldn't show off my knowledge of MySQL's magical functions.
Post Reply