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
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.

Link to comment
Share on other sites

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';");
}

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.