Jump to content

[SOLVED] Date problem


FarhanKhalaf

Recommended Posts

I have a table nordstromlisting with column datecreated filled with a unix timestamp of when the listing was created. I essentially want to delete all listings older than 5 days (432000 seconds), so I created the following sql. However, it's not working.

 

Anybody see what I'm doing wrong?

 

Thanks.

 

		$timenow = date("Y-m-d");
		$time = strtotime($timenow);

		$movetohistory = mysql_query("SELECT * INTO nordstromhistory FROM nordstromlisting WHERE '$time' - datecreated > 432000");
		$deltefromlisting = mysql_query("DELETE * FROM nordstromlisting WHERE '$time' - datecreated > 432000");	

Link to comment
Share on other sites

There's no such thing as SELECT * INTO .... At least I don't think so.

 

Change this:

$movetohistory = mysql_query("SELECT * INTO nordstromhistory FROM nordstromlisting WHERE '$time' - datecreated > 432000");

 

To:

$movetohistory = mysql_query("SELECT * INTO nordstromhistory FROM nordstromlisting WHERE '$time' - datecreated > 432000") or die(mysql_error());

 

That should display some error if there is one.

Link to comment
Share on other sites

Just read what you've written in your first post. You want to DELETE rows, so you should use DELETE query.

 

SELECT .. INTO is used for moving data from one table to another.

 

 

Link to comment
Share on other sites

A strange bit is that ''undefined variable: nordstromhistory'' is a PHP notice, not a MySQL error... Is that all you get?

 

[edit]

Seems I was wrong about what SELECT INTO is about :P

http://dev.mysql.com/doc/refman/5.0/en/select-into-statement.html

 

What you need is  INSERT ... SELECT

 

INSERT INTO nordstromhistory SELECT ... FROM nordstromlisting WHERE '$time' - datecreated > 432000

 

http://dev.mysql.com/doc/refman/5.1/en/insert-select.html

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.