Hi! On the site I'm working on, there is a new products page. When a new product is added, it is inserted into a table with all of the available products as well as a table with just new items. The rows in the new items table are what show up on the new products page. I'm trying to get rows older than 120 days to automatically drop off of the new items table, so they will no longer show up on the new products page. I have added a column to the new items table titled "date" so I should be able to set the time based on that. I.e. the person goes to the admin page today, puts in all of the information (including date) and it shows up in the new item table. After 120 days, the item the person added will no longer be there.
I added an event, (towards the bottom of the code) which from what I've read should work, and I get the error:
Parse error: syntax error, unexpected T_STRING
Clearly I'm missing something, but I'm lost. Any help would be greatly appreciated!
<?php
$currentpage = $_GET['page'];
$rowsperpage = 20;
// the offset of the list, based on current page
$offset = ($currentpage - 1) * $rowsperpage;
//find total results
$sql = "Select * FROM new_item_numbers ORDER BY 'ID' DESC";
$query = mysql_query($sql) or die(mysql_error());
$results = mysql_num_rows($query); //changed result to query
// Print out all new items with limit and offset
$sql2 = "Select *
FROM new_item_numbers
ORDER BY ID DESC
LIMIT $rowsperpage OFFSET $offset";
$query2 = mysql_query($sql2) or die(mysql_error());
$results2 = mysql_num_rows($query2);
//sets the page range
if (($offset + $rowsperpage) > $results) {
$pagerange = $results;
}elseif ($offset < $rowsperpage) {
$pagerange = $results2;
} else {
$pagerange = ($offset + $rowsperpage);
}
print "<p>Results <b>" . ($offset + 1) . "</b>-<b>" . $pagerange . "</b> of <b>$results</b></p>";
while ($row = mysql_fetch_array($query2)) {
$Item_Number = $row['Item_Number'];
$product = getProduct($Item_Number);
$long_description = getLongDescription($Item_Number);
$strip = strpos($long_description, ".") ? strpos($long_description, ".") : strpos($long_description, "!");
$long_description = substr($long_description, 0, $strip + 1); //select first sentence of long description
$new_item = "<div class='new-product'>";
$new_item .= "<a href='product_output.php?Item_Number=" . $product['Item_Number'] . "'><img src='images/" . $product['Image'] . "' alt='" . $product['Description'] . "' /></a>";
$new_item .= "<div class='description'><h3><a href='product_output.php?Item_Number=" . $product['Item_Number'] . "'>" . $product['Description'] . "</a></h3>";
$new_item .= "<p>$long_description</p></div>";
$new_item .= "<br class='clear' />";
$new_item .= "</div>";
print $new_item;
}
//Automatically delete items from new item page after 120 days
CREATE EVENT AutoDeleteNewAfter90
ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 DAY
DO
DELETE LOW_PRIORITY FROM coas50.new_item_numbers WHERE DATE < DATE_SUB(NOW(), INTERVAL 120 DAY);
//Print Pagination
$pagination = pagination($results, $rowsperpage, $currentpage, 'http://www.example.com/products/new-products.php?page=%d');
print "<br />$pagination";
?>
</div>
<?php include($_SERVER['DOCUMENT_ROOT'].'/includes/footer.php'); ?>