Stream of semiconsciousness....
Two new fields in the database: a boolean "seen", and a timestamp "seenwhen".
First, see if it's a new day.
SELECT link FROM linkstable WHERE seenwhen(I forget the MySQL, but test to see if seenwhen is "less than one day ago") ORDER BY seenwhen DESC LIMIT 1
You should be able to get away with dropping the ORDER BY ... DESC LIMIT 1; there should only be 0 or 1 record less than a day old anyway.
If you get a result,
{ then we've already rolled over to the new link for today. We've alredy fetched it. Nice, no more work here.
}
else
{ Still here? You didn't get a result? Then it's time for a new link.
SELECT id,link FROM linkstable WHERE seen=false ORDER BY seenwhen ASC LIMIT 1
If you get a result,
{ this is the new link for today. Couple of updates needed:
[b]UPDATE linkstable SET seen=true, seenwhen=NOW() WHERE id=$id[/b]
where $id is of course the id from the previous SELECT. Okay, we have our link now. No more work.
}
else
{ Still haven't got a link? That must mean that every link in the table has been seen. Fine: we'll just insist that we want to seem them all again and try once more:
[b]UPDATE linkstable SET seen=false[/b]
[b]SELECT id,link FROM linkstable WHERE seen=false ORDER BY seenwhen ASC LIMIT 1[/b]
[b]UPDATE linkstable SET seen=true, seenwhen=NOW() WHERE id=$id[/b]
If you STILL haven't got a link by this stage,
{ it's because the table is empty.
}
}
}
When inserting a new link into the table, set seen to false and seenwhen to NOW()
Warning: Maybe when I'm more awake this will look silly to me.