Jump to content

"ORDER BY" help


chester600

Recommended Posts

Hey all!

I am quite new to php/MySQL and have hit a problem during learning them.

I have created a table in my database that holds a user_id and the users age, which looks like this:

[table]
[tr][td][b]user_id[/b][/td][td][b]age[/b][/td][/tr]
[tr][td]1[/td][td]56[/td][/tr]
[tr][td]2[/td][td]70[/td][/tr]
[tr][td]3[/td][td]17[/td][/tr]
[tr][td]4[/td][td]67[/td][/tr]
[tr][td]5[/td][td]72[/td][/tr]
[tr][td]6[/td][td]60[/td][/tr]
[tr][td]7[/td][td]99[/td][/tr]
[tr][td]8[/td][td]100[/td][/tr]
[tr][td]9[/td][td]98[/td][/tr]
[tr][td]10[/td][td]200[/td][/tr]
[/table]

Now when I use this query in php:

[code]$query = "SELECT user_id, age FROM members ORDER BY age DESC";[/code]

I get the following output:
[table]
[tr][td]user_id[/td][td]age[/td][/tr]
[tr][td]7[/td][td]99[/td][/tr]
[tr][td]9[/td][td]98[/td][/tr]
[tr][td]5[/td][td]72[/td][/tr]
[tr][td]3[/td][td]70[/td][/tr]
[tr][td]4[/td][td]67[/td][/tr]
[tr][td]6[/td][td]60[/td][/tr]
[tr][td]1[/td][td]56[/td][/tr]
[tr][td]10[/td][td]200[/td][/tr]
[tr][td]2[/td][td]17[/td][/tr]
[tr][td]8[/td][td]100[/td][/tr]
[/table]

For some reason 200 is being treated as < 56 and 100 as < 17. Anyone have any ideas why this would be????

Thanks in advance!

Chester600  :)
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.