Mysql help with extra browse button
I am working on widgets that are very similar to the twitters widget, where there is a list of posts and a button for more. I can get it to work using ID variables, but I would like to sort by popular posts.
Here is my mysq code:
$sql = "SELECT id, title, category, icon_normal, status, description, views_monthly FROM posts WHERE views_monthly<=".$lastPost." AND status='1' ORDER BY views_monthly DESC LIMIT 9"
So, the problem I'm running into shows that the first 9 are just fine. When it gets to the point where views_monthly = 0, it just downloads the same message again.
How do I get it to switch to using the id when it reaches Views_monthly = 0 and downloads fresh posts?
+2
a source to share
1 answer
Instead of changing the WHERE clause, change the LIMIT offset:
SELECT id, title, category, icon_normal, status, description, views_monthly
FROM posts
WHERE status='1'
ORDER BY views_monthly DESC
LIMIT $offset, 9
The offset is the page number (based on 0) multiplied by 9. The LIMIT clause is described in the documentation for SELECT .
+3
a source to share