I have a function that I want to have update records in a database based on how old they are. I want everything over one week (7 days) old to be updated. The function I have so far is as follows:
function index_old() {
$today = date("Y-m-d");
global $mysql_table_prefix;
print "<b><br><center>Now indexing all URL's over a week old</center></b><br>\n";
$result=mysql_query("select url, indexdate, spider_depth, required, disallowed, can_leave_domain from ".$mysql_table_prefix."sites");
echo mysql_error();
while ($row=mysql_fetch_row($result)) {
$url = $row[0];
$indexdate = $row[1];
$depth = $row[2];
$include = $row[3];
$not_include = $row[4];
$can_leave_domain = $row[5];
if ($can_leave_domain=='') {
$can_leave_domain=0;
}
if ($depth == -1) {
$soption = 'full';
} else {
$soption = 'level';
}
if ($today - $indexdate > 7) {
print "<br> Indexing $url<br>";
index_site($url, 1, $depth, $soption, $include, $not_include, $can_leave_domain);
}
}
print "<br><br><center><b>Indexing finished !</b></center><br>";
}
The variable $today is supposed to define today's date, while $indexdate is supposed to define the date the record was last updated.
The problem is that when I run this, it only displays the two "print" lines ("Now Indexing..." and "Indexing Finished"), but does nothing else.
I have another function that works as it's supposed to, which updates any new records (i.e. $indexdate == ''), and is essentially the same as the above, except the line
if ($today - $indexdate > 7) {
is written as
if ($indexdate == '') {
and the variable $today is not included.
If anyone can see anything obvious in the code that is making it not work as desired, I'd appreciate it if you could help me out!
Thanks.
PS: There's more information on this issue here:
http://www.sphider.eu/forum/read.php?3,777