Reputation: 5432
I'm trying to order results of a db query based on an algorithm outside of the sql statement.
For example - each row has author_karma
and pageviews
columns. I'd like to order the result by an algorithm calculated in php after the rows are fetched...
The algorithm might look like this
$score = intval($author_karma) + (intval($pageviews)/100) + intval($age)
In sites like hacker news is this calculated in the sql query? How do they make this work? If I try to store the score in the db, how often to I update it (especially when time is involved in the score)?
Upvotes: 0
Views: 98
Reputation: 30170
You can easily do it in the query
select this, that, other, (author_karmar + ( pageviews/100 ) + age ) as score from table order by score desc
Upvotes: 2