drstop Posted April 25, 2010 Share Posted April 25, 2010 Hi, I know its something really simple, but after 2 days of searching around I finally decided to give up... here is the issue: I have a mysql table with topics and the number of time they have been read the "number of reads" is called READS and is INT(11) I <b>CAN</b>order ascending/descending when I do it in phpmysql, no problems in PHP, running a simple query like SELECT * FROM stories ORDER BY 'reads' DESC" produces zero rows :'( All other fields ORDER BY without problems the field has ONLY numbers I am getting kinda crazy here... any possible hints as to where the problem can be? Will GLADLY describe anything that might help you help me With best regards Alexander Quote Link to comment https://forums.phpfreaks.com/topic/199715-order-by-acting-strange/ Share on other sites More sharing options...
Mchl Posted April 25, 2010 Share Posted April 25, 2010 You're using ' (quotes) instead of (`) backticks around 'reads', although this should not limit number of rows fetched. Can you paste the actual code you use? Quote Link to comment https://forums.phpfreaks.com/topic/199715-order-by-acting-strange/#findComment-1048222 Share on other sites More sharing options...
lampstax Posted April 25, 2010 Share Posted April 25, 2010 Not 100% sure this is why you're getting 0 result, but try replacing the ORDER BY 'reads' DESC with ORDER BY `reads` DESC. I think the way you are quoting 'reads' makes mysql process that as a value, and not a table column. Quote Link to comment https://forums.phpfreaks.com/topic/199715-order-by-acting-strange/#findComment-1048225 Share on other sites More sharing options...
lampstax Posted April 25, 2010 Share Posted April 25, 2010 Looks like Mchl beat me to it. Quote Link to comment https://forums.phpfreaks.com/topic/199715-order-by-acting-strange/#findComment-1048228 Share on other sites More sharing options...
drstop Posted April 26, 2010 Author Share Posted April 26, 2010 backticks actually helped!!!!!!!!!!!!!!!!!!!!!! Interesting that no quotes (backticks) still doesnt produce any result. In the same table, have a field called ID (exactly same thing, INT(11)) SELECT* FROM stories ORDER BY id <--- works perfectly SELECT* FROM stories ORDER BY reads <---- doesnt work But backticks solved it!! Thanks ALOT for your help! Quote Link to comment https://forums.phpfreaks.com/topic/199715-order-by-acting-strange/#findComment-1048339 Share on other sites More sharing options...
PFMaBiSmAd Posted April 26, 2010 Share Posted April 26, 2010 READS is a reserved mysql keyword and produces an error when used as a column name. The back-ticks `` denotes special handling and allows a reserved keyword to be used as a column name. Quote Link to comment https://forums.phpfreaks.com/topic/199715-order-by-acting-strange/#findComment-1048340 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.