Why move them? Let's say you move the links to a SQL database. Each row will have a unique ID (well, each row should have a unique ID) and it would need a timestamp field. So your table might look like:
CREATE TABLE `links` (
`id` INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`url` TEXT NOT NULL,
`last_used` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
) ENGINE = MYISAM;
Now, given that table, we can have say 20 links. So we'll have IDs 1 through 20. Now it's just a matter of a series of queries.
<?php
function getLink()
{
$query = "SELECT `id`, `url` FROM `links` WHERE `last_used` = NOW() ORDER BY `last_used` DESC LIMIT 1";
$result = mysql_query($query) or die('SQL Error: ' . mysql_error());
// There is already a link defined for today... return the URL
if(mysql_num_rows($result) == 1)
{
$row = mysql_fetch_assoc($result);
return $row['url'];
}
// Was there one yesterday?
$query = "SELECT `id` FROM `links` WHERE `last_used` = DATE_SUB(NOW(), INTERVAL 1 DAY)";
$result = mysql_query($query) or die('SQL Error: ' . mysql_error());
// There wasn't one yesterday, let's just get the first link
if(mysql_num_rows($result) < 1)
$linkID = getFirstLinkID();
// Let's get the next ID after the one from yesterday...
else
{
$row = mysql_fetch_assoc($result);
$query = "SELECT `id` FROM `links` WHERE `id` > " . intval($row['id']) . " LIMIT 1";
$result = mysql_query($query) or die('SQL Error: ' . mysql_error());
// If there is no ID that's greater, get the first link
if(!$result || mysql_num_rows($result) < 1)
$linkID = getFirstLinkID();
else
{
$row = mysql_fetch_assoc($result);
$linkID = $row['id'];
}
}
// Get the link URL:
$query = "SELECT `url` FROM `links` WHERE `id` = " . intval($linkID);
$result = mysql_query($query) or die('SQL Error: ' . mysql_error());
$row = mysql_fetch_assoc($result);
// Update it so subsequent calls are faster ;)
$query = "UPDATE `links` SET `last_used` = NOW() WHERE `id` = " . intval($linkID);
$result = mysql_query($query) or die('SQL Error: ' . mysql_error());
return $row['link'];
}
function getFirstLinkID()
{
$query = "SELECT `id` FROM `links` ORDER BY `id` ASC LIMIT 1";
$result = mysql_query($query) or die('SQL Error: ' . mysql_error());
$row = mysql_fetch_assoc($result);
return $row['id'];
}
It's quite a few queries, but it works. I'm sure it could be trimmed down, but I wasn't going for efficiency, just a kind of "proof of concept".