I am creating a news feed and am trying to allow three news updates (per person) at a time.
The structure of the MYSQL db is as follows:
username|update1|update2|update3
bill foo bar baz
I am wondering how I can make it so that when bill posts a new news update:
update3
would be removedupdate2
would be moved to update3
update1
would be moved to update2
update1
Would this be possible in simply a MYSQL query or would I have to use PHP to do this?
Try this:
UPDATE table
SET update3 = update2,
update2 = update1,
update1 = {$your_input}
WHERE your_filter = your_condition
Instead of denormalizing the data like that, keep it pure:
timestamp|username|update
Then the last three updates can always be obtained with
select *
from updates
where username = 'the user'
order by timestamp descending
limit 3