If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > error in retriving data from the database

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-01-09, 11:48
hscorp hscorp is offline
Registered User
 
Join Date: Mar 2009
Posts: 11
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??
Reply With Quote
  #2 (permalink)  
Old 03-01-09, 11:57
shammat shammat is offline
Registered User
 
Join Date: Nov 2003
Posts: 2,407
looks like the column hits is defined as VARCHAR (or CHAR). You should change that to a numeric datatype (e.g. INTEGER)
Reply With Quote
  #3 (permalink)  
Old 03-01-09, 11:58
hscorp hscorp is offline
Registered User
 
Join Date: Mar 2009
Posts: 11
would that effect with the script?
Reply With Quote
  #4 (permalink)  
Old 03-01-09, 12:04
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
Quote:
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
Reply With Quote
  #5 (permalink)  
Old 03-01-09, 15:46
hscorp hscorp is offline
Registered User
 
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On