update four records daily out of six records----mysql---php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
LuckyBoyEver
Forum Newbie
Posts: 2
Joined: Thu Jan 21, 2016 12:54 pm

update four records daily out of six records----mysql---php

Post by LuckyBoyEver »

Image
Image
Image
Image
I have a table containing 6 records i want to display first four records today and today date should be saved against those 4 records.On the next day remaining two records should be displayed and first two records as well and date should be saved and flag should b incremented as well. i hope you guys are getting my point
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: update four records daily out of six records----mysql---

Post by Christopher »

LuckyBoyEver wrote:I have a table containing 6 records i want to display first four records today and today date should be saved against those 4 records.On the next day remaining two records should be displayed and first two records as well and date should be saved and flag should b incremented as well. i hope you guys are getting my point
What you want to do seems strange. Is it just the first four records when "ORDER BY person_id DESC" ? I ask because a database does not really have a "first four records". You can SELECT records by many criteria and sort them ascending/descending by any field.

If that is that is really what you want to do, then maybe something like:

Code: Select all

UPDATE mytable SET duty_flag=duty_flag+1, last_dty_timestamp=NOW() ORDER BY person_id DESC LIMIT 4
It would be a better design to be able to SELECT the rows you want to update based on values in their fields.
(#10850)
LuckyBoyEver
Forum Newbie
Posts: 2
Joined: Thu Jan 21, 2016 12:54 pm

Re: update four records daily out of six records----mysql---

Post by LuckyBoyEver »

there are total 6 persons and 4 duties........everyday 4 person will b on duty......next day remaining 2 and previous 2 will perform duty....
the one today on duty will increment his flag and update date as well
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: update four records daily out of six records----mysql---

Post by Christopher »

Search for "mysql round robin select". It is a little complicated. It may be easier to generate a schedule for the 24 day cycles in a separate table.
(#10850)
Post Reply