Jump to content

Greatest to least help


Imad

Recommended Posts

Hi Guys, I have a MySQL query going on here which is suppose to bring the top 20 threads based on the most views threads to the least. Here's the query:

 

  $query = "SELECT * FROM threads ORDER BY views DESC limit 20";

 

However, it doesn't seem to put the most viewed thread first to the least, it's just scattered around. It brings a 5,000 viewed thread second on the list compared to a 5 views thread.

Any ideas?

Best Regards.

 

Link to comment
https://forums.phpfreaks.com/topic/133443-greatest-to-least-help/
Share on other sites

However, it doesn't seem to put the most viewed thread first to the least, it's just scattered around. It brings a 5,000 viewed thread second on the list compared to a 5 views thread.

Any ideas?

Best Regards.

 

 

It could be because your field type for the view count is something like varchar when it should be integer (int).

I just removed the limit and it brought back the same results. If I do it by thread id it works perfectly fine, but when I do it with the views it messes up.

 

EDIT: I figured the problem out. I didn't create the views column properly, I just replaced it to this:

 

views int unsigned NOT NULL default '0',

 

and it worked fine. Thanks for your help guys. :D

 

EDIT again: @EternalSorrow, exactly right. :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.