Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2009
    Posts
    11

    Unanswered: error in retriving data from the database

    i made this code

    Code:
    $latest = mysql_query('SELECT * FROM file ORDER BY hits ASC LIMIT 50')
    to get the file names and order it by hits

    but i get order like that

    15
    2
    25
    3
    31

    i want it to be like

    2
    3
    15
    25
    31

    what's wrong??

  2. #2
    Join Date
    Nov 2003
    Posts
    2,935
    Provided Answers: 12
    looks like the column hits is defined as VARCHAR (or CHAR). You should change that to a numeric datatype (e.g. INTEGER)

  3. #3
    Join Date
    Mar 2009
    Posts
    11
    would that effect with the script?

  4. #4
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    what's wrong??
    Looks like the field hits is a character field and it's ordering things alphabetically. You can either rebuild the table with that field set to int (the proper way) or you could try either :
    Code:
    select * from file order by cast( hits as signed);
    select * from file order by hits + 0;
    You could use the following to see how you've defined the table :
    Code:
    show create table file;
    Mike

    PS I must of been slow typing, didn't realise someone else had answered

  5. #5
    Join Date
    Mar 2009
    Posts
    11
    thank you guys

    i changed it to int(255) and now working fine i hope it doesn't affect with the script

    i really appreciate it

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •