OK. I can't test it out right now cuz I'm getting my web hosting company to upgrade the version of MySQL that's available, but here's what I have. Does it look right?
$connresult = @mysql_connect("myDatabase","myUser","myPassword");
if (!$connresult)
{
$problemtext = 'Error opening a db connection.\r\n'.mysql_error($connresult);
trigger_error($problemtext, E_USER_ERROR);
}
$db_selected = @mysql_select_db('ownersfinancingrealestate_com_-_listingsdb', $connresult);
if (!db_selected)
{
$problemtext = 'Error selecting MySQL db.\r\n'.mysql_error($connresult);
trigger_error($problemtext, E_USER_ERROR);
}
//For MySQL 4.0.11 and higher
START TRANSACTION;
//For MySQL 3.23.19
BEGIN WORK;
$insert_query = "INSERT INTO `ofrearchive`
SELECT * FROM `ofrelistings` LEFT JOIN `ofrearchive` USING(uniqueid)
WHERE `ofrearchive.uniqueid` IS NULL AND DATEDIFF(`ofrelistings.dateadded`, now())>30";
$insert_result = mysql_query($insert_query);
if (!insert_result)
{
ROLLBACK;
$problemtext = 'Error INSERT-ing information into archive table.\r\n'.mysql_error($connresult);
trigger_error($problemtext, E_USER_ERROR);
}
$delete_query = "DELETE `ofrelistings.*` FROM `ofrelistings` INNER JOIN `ofrearchive` USING(uniqueid)";
$delete_result = mysql_query($delete_query);
if (!$delete_result)
{
ROLLBACK;
$problemtext = 'Error DELETE-ing information from main table.\r\n'.mysql_error($connresult);
trigger_error($problemtext, E_USER_ERROR);
}
$select_query = "SELECT * FROM `ofrelistings` INNER JOIN `ofrearchive` USING(uniqueid)";
$select_result = mysql_query($select_query);
if (!select_result)
{
echo 'Backup worked successfully';
}
else
{
ROLLBACK;
$problemtext = 'Error completing the backing up of information from main table to archive table.\r\n'.mysql_error($connresult);
trigger_error($problemtext, E_USER_ERROR);
}
$searchstring = "SELECT * FROM `ofrelistings` WHERE blahblahblahblah";
$searchresults = mysql_query($searchstring);
if (!$searchresults)
{
ROLLBACK;
$problemtext = 'Error searching OFRE listings db.\r\n'.mysql_error($connresult);
trigger_error($problemtext, E_USER_ERROR);
}
//If no errors occurred, then commit transactions
COMMIT;
$numrows = mysql_num_rows($searchresults);
if ($numrows == 0)
{
echo "No results matched your search criteria";
require('/home/virtual/ofre.com/var/www/includes/copyright.php');
require('/home/virtual/ofre.com/var/www/includes/closetables.php');
exit;
}
//Retrieve, check, and print results
while ($row = mysql_fetch_assoc($searchresults))
{
//echo out results in a table including handling pics
}
//free up result memory
mysql_free_result($searchresults);