Jump to content


move data from table to another

  • Please log in to reply
1 reply to this topic

#1 vietboy505

  • Members
  • PipPip
  • Member
  • 16 posts

Posted 24 March 2006 - 04:41 AM

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?

<?php include("config.php"); ?> 
//INFO from mySQL 
//name VARCHAR(30), 
//status VARCHAR(1), 
//dateModify TIMESTAMP,  
$overWeek=date('Y-m-d H:i:s', strtotime('+1 week'));
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());  



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

#2 ober

  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 24 March 2006 - 02:15 PM

You cannot combine queries like that. You have to run the SELECT query, store the values in variables and then create a second query for the insert.

Info: PHP Manual

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users