Forum Moderators: coopster

Message Too Old, No Replies

ordering problems

not working...

         

PokeTech

10:04 pm on Nov 6, 2008 (gmt 0)

10+ Year Member



Well I'm retrieving information from a mysql database and I want to display the information in Order by level and I've done this loads of times before but for some reason its not working. This is my query:

$query = "SELECT * FROM table ORDER BY level LIMIT 20";
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result)) {

code here

}

And when I go to the page it displays it like this:

2
31
4
344
5
3
4857
4389
48
2839
1
34
908
etc...

For some reason its doing that and I have no idea why. I'm just trying to order them from greatest to least.

Any help would be appreciated!

LifeinAsia

10:20 pm on Nov 6, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



First, if you want to go from greatest to least (i.e. descending order), you need to use "ORDER BY level DESC"

Second, what field type is level?

PokeTech

10:53 pm on Nov 6, 2008 (gmt 0)

10+ Year Member



Well it was text, then I changed it to varchar and neither of those seemed to work until I turned it to decimal and then it worked fine. Thanks I guess you sorta helped.

LifeinAsia

11:26 pm on Nov 6, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Yup- text data does not sort the same was as numeric data. "123" is NOT the same as 123.