jomagi Posted January 28, 2009 Share Posted January 28, 2009 Hi there! Can't make it work, I want to move a record from table1 to table2 by selecting a field name from table1 to match name of table2. The 2 tables are the same structure minus auto-increment in table2. Can anyone help me? Thanks. <?php require_once('Connections/destaques.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } if ((isset($_GET['id'])) && ($_GET['id'] != "")) { $query = sprintf("SELECT * FROM destaques WHERE id=%s", GetSQLValueString($_GET['id'], "int")); $result = mysql_query($query); $row = mysql_fetch_array($result); $editname = $row["editora"]; $moveSQL = "INSERT INTO '$editname' VALUES ('','$row["id"]','$row["editora"]','$row["artista"]','$row["disco"]','$row["ref"]','$row["imagem"]','$row["estilo"]')"; $action = mysql_query($moveSQL); $deleteSQL = sprintf("DELETE FROM destaques WHERE id=%s", GetSQLValueString($_GET['id'], "int")); mysql_select_db($database_destaques, $destaques); $Result1 = mysql_query($deleteSQL, $destaques) or die(mysql_error()); $deleteGoTo = "admin_destaques.php"; if (isset($_SERVER['QUERY_STRING'])) { $deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?"; $deleteGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $deleteGoTo)); } ?> Link to comment https://forums.phpfreaks.com/topic/142823-move-data-between-tables/ Share on other sites More sharing options...
landavia Posted January 30, 2009 Share Posted January 30, 2009 theres no query that able to move table CREATE TABLE `bintaro_medrec`.`terkini` ( `ID` int( 5 ) NOT NULL AUTO_INCREMENT , `KATEGORI` int( 1 ) default NULL , `HARI` varchar( 6 ) default NULL , `TANGGAL` varchar( 20 ) default NULL , `KOTA` varchar( 30 ) default NULL , `JUDUL` varchar( 200 ) default NULL , `ABSTRAK` varchar( 250 ) default NULL , `IMAGE1` varchar( 50 ) default NULL , `IMAGE2` varchar( 50 ) default NULL , `EXPIRE` int( 1 ) NOT NULL default '0', `CONTENT` text, PRIMARY KEY ( `ID` ) , UNIQUE KEY `id` ( `ID` ) , KEY `id_2` ( `ID` ) , KEY `expire` ( `EXPIRE` ) , KEY `EXPIRE_2` ( `EXPIRE` ) ) ENGINE = MYISAM DEFAULT CHARSET = latin1 AUTO_INCREMENT =99; INSERT INTO `bintaro_medrec`.`terkini` SELECT * FROM `bintaro_backup`.`terkini` ; DROP TABLE `bintaro_backup`.`terkini` ; try copy this script 1. copy all data from table1 to table2 2. drop table 1. 3. check.. if any of the process error Link to comment https://forums.phpfreaks.com/topic/142823-move-data-between-tables/#findComment-750463 Share on other sites More sharing options...
jomagi Posted February 3, 2009 Author Share Posted February 3, 2009 How can I catch the name field of table1 and make it correspond with table2 name? ??? Link to comment https://forums.phpfreaks.com/topic/142823-move-data-between-tables/#findComment-753550 Share on other sites More sharing options...
jomagi Posted February 4, 2009 Author Share Posted February 4, 2009 Nobody can give a hand? ??? Link to comment https://forums.phpfreaks.com/topic/142823-move-data-between-tables/#findComment-754300 Share on other sites More sharing options...
jomagi Posted February 4, 2009 Author Share Posted February 4, 2009 Please help me, I need it so much!!!! Link to comment https://forums.phpfreaks.com/topic/142823-move-data-between-tables/#findComment-754407 Share on other sites More sharing options...
landavia Posted February 6, 2009 Share Posted February 6, 2009 How can I catch the name field of table1 and make it correspond with table2 name? ??? u need a script to build a same table.. sry.. late respond hmm.. u should try it out.. after build table2.. then copy to table 2 plzz.. remind to backup DB *is happen 2 me AGAIN Link to comment https://forums.phpfreaks.com/topic/142823-move-data-between-tables/#findComment-756161 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.