Show the Latest Message Fully with Per Page, Limit

PHP is a very popular and widely-used open source server-side scripting language, often used for developing web applications and message modules.

Teguh Arief

Published on: September 24, 2020

Categories:PHP
Share:

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

Optimizing Site Performance with PHP Image for SEO

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
Illustration of sending multiple emails.

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