Jump to content

Deleting old/expired listings...


xtrafile

Recommended Posts

Hi there,

 

I have this code:

 

$expires = expires-" . $coupon->id . ";

if ($expires < date("m/d/y")) {

$expires = "true";

mysql_query("DELETE FROM `coupon`");

 

}

 

When i run the page

it should delete from the query all the old listings that no longer exist.

 

How can I update this?

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/91802-deleting-oldexpired-listings/
Share on other sites

You need to put a WHERE clause on your DELETE statement for SQL or you're going to delete all entries in the coupon table.  The WHERE clause should clearly identify one (or several) rows as those you want to have deleted.  From the block of code you have given, it is impossible to guess what those identifiers might be.

a few things, you have syntax errors, cannot use formmated date as an integer, and you will delete all rows.

 

to fix your code to what i think you mean:

 

if (strtotime($expiretime) < time()) {
$expired = "true";
mysql_query("DELETE FROM `coupon` WHERE `id`='$coupon->id';");
}

mysql_query("DELETE FROM `coupon` WHERE `exp`<='".time());

 

this is all you should ever need tbh, i dont get what your trying to do with this:

 

$expires = expires-" . $coupon->id . ";

 

the strtotime() function only accepts formatted dates and times, eg: Feb 16 08

 

putting that $expires = variable will break this code as "expires-" is not anything to do with dates or times.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.