
Teguh Arief
Published on: September 24, 2020
Are you developing a message module and need to show the latest message fully while also presenting previous messages with robust per-page and limit capabilities? Administrators often require the most recent notification to be immediately visible on a user's dashboard, followed by an organized display of older messages. This guide addresses just that, demonstrating how to sort messages in reverse chronological order and implement pagination, such as showing 5 messages per page on the user's dashboard.
Implementing this functionality is straightforward. Here's how you can show only 1 latest message fully:
SELECT * FROM message WHERE status = 'Published' ORDER BY id DESC LIMIT 1
For displaying another 20 previous messages (with 5 messages per page), leveraging the per-page and limit concept, consider the following SQL:
SELECT * FROM (SELECT * FROM message WHERE status = 'Published' ORDER BY id DESC LIMIT 1 , 20 )t LIMIT 0 , 5
Related Posts

Send Multiple Email Blasts to a Single Email Recipient
Learn to send multiple email blasts to a single recipient for promotions. This guide covers effective system design and implementation for your business.
Read More
Optimizing Site Performance with PHP Image for SEO
Boost site speed & SEO with PHP image optimization. Learn practical tips to improve user experience and search rankings.
Read More
Fixing 404 GSC for JavaScript Rendered Page
Learn how to resolve 404 errors in Google Search Console for JavaScript-rendered pages by redirecting crawlers to HTML or PHP alternatives using .htaccess
Read More