Location: PHPKode > scripts > Quotations Database > quotations-database/admin/delete_old_quotes.php
<?
/*
--------------------------------------------------
:::: Quotations Database ::::
--------------------------------------------------
PHP & MySQL application that stores quotations and author information, 
allows scheduling for 'quote of the day' and weekly themes.
Includes an administration interface to allow for easy updates and maintenance.
Copyright (C) 2009  Robert Temple
--------------------------------------------------

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

You can contact the author at hide@address.com
Please do not remove the author, copyright, or license info.
*/


// Initialize session and check to make sure user is registered and logged in
include "include/session.php"; 

// Connect  to database
include "include/connect.php";
dbconnect();

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
	<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
	<title> Delete Schedueled Quotes Older than 90 Days</title>		
    <link href="../quotation.css" rel="stylesheet" type="text/css">
</head>
<body>


<?

// If user clicks Submit, run a DELETE. Otherwise, ask for confirmation.
if ($_POST['Submit']) {
	// Select entries from the FutureQuotes table older than 90 days using strtotime():
$threeMonthsAgo = date('Y-m-d', strtotime('-90 days'));
	$DelString = "DELETE FROM FutureQuotesTBL WHERE QuoteDate <= $threeMonthsAgo";
// Run the deletion
		$result = mysql_query($DelString) or die ("Invalid query"); 
		
// Confirm the deletion, add link to admin home:
        echo "<table width=\"550\" border=\"0\" align=\"center\" cellpadding=\"4\" bgcolor=\"#FFFFFF\"><tr><td bgcolor=\"#FFCC00\"><span class=\"header\"><br>Delete Schedueled Quotes Older than 90 Days</span>&nbsp;&nbsp;<a href=\"index.php\">Admin Home</a><br>&nbsp;</td></tr>";
		echo "<tr><td class=\"bodyCopy\">Schedueled quotes older than 90 days were deleted from the database.</td></tr>";
		echo "<tr><td class=\"bodyCopy\"><a href=\"index.php\">Admin Home</a></td></tr></table>\n";	



}  else { 
	
$threeMonthsAgo = date('Y-m-d', strtotime('-90 days'));
	
	$query = "SELECT * FROM FutureQuotesTBL where QuoteDate <= $threeMonthsAgo";	

	$result = mysql_query($query) or die ( mysql_error() );
	$num_rows = mysql_num_rows($result); 
	
	if (strval($num_rows) == "0"){
	
	 echo "<table width=\"550\" border=\"0\" align=\"center\" cellpadding=\"4\" bgcolor=\"#FFFFFF\"><tr><td bgcolor=\"#FFCC00\"><span class=\"header\"><br>Delete Schedueled Quotes Older than 90 Days</span>&nbsp;&nbsp;<a href=\"index.php\">Admin Home</a><br>&nbsp;</td></tr>";
		echo "<tr><td class=\"bodyCopy\">There are no records older than 90 days in the database.</td></tr>";
		echo "<tr><td class=\"bodyCopy\"><a href=\"index.php\">Admin Home</a></td></tr></table>\n";
	
	} else {


?>
<table width="550" border="0" align="center" cellpadding="1" cellspacing="0" bgcolor="#000000">
      <Tr>
        <Td>
<table width="548" border="0" align="center" cellpadding="1" bgcolor="#FFFFFF">
  <tr>
    <td bgcolor="#FFCC00"><br>
          <span class="header">Delete Schedueled Quotes Older than 90 Days</span><br>
&nbsp;&nbsp;&nbsp;<a href="index.php">Admin page</a><br>
&nbsp;
</td>
  </tr>
<Tr>
  <Td bgcolor="#cccccc"></Td>
</Tr>
<tr><td><form method=post action="<? echo $PHP_SELF; ?>">
      <table width="300" align="center" cellpadding="2">
        <tr>
          <td align="center" class="warningHeader">Confirm Delete</td>
        </tr>
        <tr>
          <td align="left" class="bodyCopy">This will delete <?php echo strval($num_rows) ?> records from the database. Are you sure?<br><br>
This action cannot be undone. <br>
	<a href="index.php">Click here to cancel.</a></td>
        </tr>
        <tr>
          <td align="center"></td>
        </tr>
         <tr>
          <td align="center"><input type="Submit" name="Submit" class="bodyCopy" value="Yes"></td>
        </tr>
      </table>
    </form></td>
  </tr>
  <Tr>
  <Td bgcolor="#cccccc">
</Td>
</Tr>
<Tr>
  <Td align="center"><br>
  <a href="qotd_schedule.php">Show quotation schedule</a><br>
<br>
&nbsp;</Td>
</Tr>
</table>
</td>
  </tr>
</table>
<?
}}	
?>
</body>
</html>
Return current item: Quotations Database