Page 1 of 1

Site Message Function

Posted: Thu Jun 19, 2008 12:03 pm
by mrgooding
Hi All

I'm after a bit of help with a problem implementing a site message function (the idea is admin's can post site messages that appear on any users homepage, after logging in, but it will only display the last two site messages)

I've managed to store the site messages without problem, but it's recalling them and displaying them that's causing me to scratch my head copiously. My problem is the way to only show the last two site messages - i've thought of a couple of ways of implementing this, but was wondering if anyone could clarify the best (and preferably simplest!) way of achieveing this:

1. A timestamp field - I believe this would involve a bit of coding to check out of x records which two are the most recent
2. A counter field - The first site message gets assigned 1 as it's counter value, then each subsequent message gets this +1
3. Just using the last two rows in the database - presumably these would be the most recent, but i'm not sure if this is a bit of a dodgy method.

I'd appreciate anyones input on this :D

Re: Site Message Function

Posted: Thu Jun 19, 2008 12:09 pm
by Frozenlight777
adjust your query to be something like this.

Code: Select all

select * from messages ORDER BY message_id DESC limit 2
that should give you the last 2 (most recent) messages

Re: Site Message Function

Posted: Thu Jun 19, 2008 12:11 pm
by mrgooding
Excellent! That will make it nice and simple.

Thanks for your assistance, Frozenlight777 :)