A new expirydataviewer
At some point I need to create a new version of the Expiry Data Viewer (to replace the previous version) that will extract the data from the MySQL database. This seems relatively easy, so I'm doing it now before finishing the Expiry Checker.
This script seems to be OK...
<?php
/*
// EXPIRY DATA VIEWER - version 2.1
//
// This script is designed to accompany "expirychecker.php4"; it
// allows users to view the previous week's expiry data, which is
// stored in "ExpiryDataLastWeek.xml".
//
//
// martin.bush@lsbu.ac.uk, August 2006.
//
//
// Permission is granted to re-use all or part of this software
// under the terms of the GNU General Public License as published
// by the Free Software Foundation [www.gnu.org/copyleft/gpl.html].
// The author would very much appreciate being informed about any
// re-use of this software . . . thanks!
*/
function connect_to_db() {
if ($db = @mysql_connect("mysql.lsbu.ac.uk", "bushm", "****")) {
if (@mysql_select_db("bushm", $db)) {
return $db;
} else {
die("<h3>Failed to obtain access to database. Please
try again later, or contact martin.bush@lsbu.ac.uk if the problem
persists.</h3>");
}
} else {
die("<h3>Failed to obtain access to database. Please
try again later, or contact martin.bush@lsbu.ac.uk if the problem
persists.</h3>");
}
}
//================================================================
/*
// MAIN PROGRAM
*/
// Display preamble HTML
echo "<html><head><title>Expiry Checker: ";
echo "List of expired web pages as of last week.";
echo" </title></head><body><pre>";
echo "<b><u>Expiry Checker: ";
echo "List of expired web pages as of last week.";
echo "</u></b>\n";
echo " (Generated on ".date('l dS \of F Y h:i:s A').")\n\n";
$db = connect_to_db();
// in case the expirydataLASTWEEK table doesn't exist
$sql = "SHOW COLUMNS FROM expirydataLASTWEEK";
$result = mysql_query($sql, $db);
if ($result == FALSE) {
echo "Woops - there seems to be a problem with the database.";
echo "\n\nPlease try again later, or contact ";
echo "martin.bush@lsbu.ac.uk if the problem persists.";
} else {
// in case the expirydataLASTWEEK table contains no data
$sql = "SELECT * FROM expirydataLASTWEEK";
$result = mysql_query($sql, $db);
if (mysql_num_rows($result) == 0) {
echo "There were no expired pages recorded last week.";
} else {
while ($expired_page = mysql_fetch_row($result)) {
$url = trim($expired_page[1]);
$expirydate = trim($expired_page[2]);
$owner = trim($expired_page[3]);
$message = trim($expired_page[4]);
echo "<a href=\"";
echo $url;
echo "\">";
echo $url;
echo "</a>";
echo "\nOwner = ";
echo "<a href=\"mailto:";
echo $owner;
echo "\">";
echo $owner;
echo "</a>";
echo ", Expired = ";
echo $expirydate;
// echo "\nMessage = ";
// echo $message;
echo "\n\n";
}
}
}
// Display ending HTML
echo "</pre></body></head>";
?>