Show the Latest Message Fully with Per Page, Limit

Teguh Arief

Sep 24, 2020

Share article to

PHP is a very popular and widely-used open source server-side scripting language. Doc. Kinsta.com.

I'm currently developing a message module. Administrator want to show the latest message fully and previous messages with per page and limit on the users notification area on the Dashboard. Sort in reverse chronological order when showing on user's dashboard. Add a pagination, to show 5 message per page on user's dashboard.

 

Its actually simple. You can do it like this: Only 1 Latest Message Fully


SELECT *
FROM message
WHERE status = 'Published'
ORDER BY id DESC
LIMIT 1


Another 20 Previous Messages (with 5 message per page)


SELECT *
FROM (SELECT *
FROM message
WHERE status = 'Published'
ORDER BY id DESC
LIMIT 1 , 20
)t
LIMIT 0 , 5


 

Related Posts