TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   Order by top rated? (http://www.talkphp.com/general/1425-order-top-rated.html)

Sled 11-10-2007 01:13 PM

Order by top rated?
 
Hey,
I've installed this ajax rating script on my site, and I'd like to have a list with 5 items, ordered by top rated.
Thins are stored like this in database: there's a column with the total votes, and a column with total value. (this is to make sure every vote has same importance)
Now to order them I'd need to do something like order by totalvalue/totalvotes.
But I have no idea how to do that ...
Any suggestions please?

Thanks!

CMellor 11-10-2007 04:58 PM

Hey, I'm pretty sure I know what AJAX rating bar your talking about, I used the base of it's code to make my own. This answer isn't 100% going to be what you want, but I like to attempt to help :) Try:

PHP Code:

ORDER BY totalvalue totalvotes DESC // or ASC, whatever 


bluesaga 11-13-2007 09:58 AM

Quote:

Originally Posted by CMellor (Post 3893)
Hey, I'm pretty sure I know what AJAX rating bar your talking about, I used the base of it's code to make my own. This answer isn't 100% going to be what you want, but I like to attempt to help :) Try:

PHP Code:

ORDER BY totalvalue totalvotes DESC // or ASC, whatever 


That isnt a neat way of doing it, the following would be better:

PHP Code:

SELECT (totalvalue totalvotes) as valbyvotes FROM table ORDER BY valbyvotes DESC 


Sled 11-13-2007 08:12 PM

Thanks guys, I didn't know you could use "/" in queries.
I should be able to get further now :)


All times are GMT. The time now is 02:38 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0