move data from table to another table

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
vietboy505
Forum Commoner
Posts: 53
Joined: Wed Feb 22, 2006 9:30 am

move data from table to another table

Post by vietboy505 »

I want to move the row from OLD TABLE to NEW TABLE where:
the OLD TABLE, status == 'S' & the dateModify is over a week, move that row (all data to the NEW TABLE).
Then delete that row on the OLD TABLE.
I try the code below, nothing happen, no data is output. I try to change to +1 day, it's still same but it should display the data a day old.

How can I fix that?

Code: Select all

<?php include("config.php"); ?> 
<?php
//INFO from mySQL 
//id INT NOT NULL AUTO_INCREMENT, 
//PRIMARY KEY(id), 
//name VARCHAR(30), 
//status VARCHAR(1), 
//dateModify TIMESTAMP,  
$overWeek=date('Y-m-d H:i:s', strtotime('+1 week'));
$statusCheck="S"; 
mysql_select_db($dbnameNAME) or die(mysql_error()); 

 $result = mysql_query("INSERT INTO $tableNEW 
        (name, status, dateModify) 
        SELECT name,status,dateModify FROM $tableOLD WHERE status = '$statusCheck' AND dateModify >= '$overWeek' " ) 
    or die($errCon . mysql_error());  

?>

<?php

mysql_select_db($dbnameNAME) or die(mysql_error());
$result2 = mysql_query("SELECT * FROM $tableNEW ")
or die(mysql_error());

while($row2 = mysql_fetch_array($result2)) {

    echo $row2['name'];
    echo $row2['status'];
    echo $row2['dateModify'];

}

//free up memory
mysql_free_result($result2);
?>
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

Shouldn't it be -1 week?
vietboy505
Forum Commoner
Posts: 53
Joined: Wed Feb 22, 2006 9:30 am

Post by vietboy505 »

True..

I want all date before starting -1 week ago.

I try to put this in SQL statement and it doesn't work. In fact, I do have data before that date.

Code: Select all

dateModify <= '$overWeek'
Post Reply