Southern Belle Posted March 13, 2008 Share Posted March 13, 2008 I want to create an exact copy of an existing table, structure and data. I want to make some changes to the temp table then delete it when I'm through. Is there a function to do this? If not how would you suggest I do this. Link to comment https://forums.phpfreaks.com/topic/95999-copy-table-content-and-structure/ Share on other sites More sharing options...
Southern Belle Posted March 13, 2008 Author Share Posted March 13, 2008 Do you need more info or is this a really dumb question ??? Link to comment https://forums.phpfreaks.com/topic/95999-copy-table-content-and-structure/#findComment-491539 Share on other sites More sharing options...
sasa Posted March 13, 2008 Share Posted March 13, 2008 CREATE TEMPORARY TABLE new_tbl SELECT * FROM orig_tbl Link to comment https://forums.phpfreaks.com/topic/95999-copy-table-content-and-structure/#findComment-491548 Share on other sites More sharing options...
Southern Belle Posted March 14, 2008 Author Share Posted March 14, 2008 I want to create a duplicate of a user requested table (temp) and delete all rows that don't match the their criteria. Then display the matches (what's left). OK, here's the code I'm using... // make sure all info provided if (($test1 == "test1" && $test2 == "test2") || $table == "") echo "Try again - enter what you need to enter."; else { $result = @mysql_query("CREATE TEMPORARY TABLE temp SELECT * FROM $table"); if (!$result) { exit("<p> Error performing query LINE 29" . mysql_error() . "</p>"); } WHILE ($row = mysql_fetch_array($result)) { echo "row " . $row; $sql = "DELETE FROM temp WHERE animal != $test1 AND transport != $test2"; } } and this is the error meg I'm getting: [tt]Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\www\vhosts\touchtheworldweb.com\httpdocs\php\search_REDO3.php on line 35[/tt] What am I doing wrong? Link to comment https://forums.phpfreaks.com/topic/95999-copy-table-content-and-structure/#findComment-492240 Share on other sites More sharing options...
sasa Posted March 14, 2008 Share Posted March 14, 2008 CREATE TEMPORARY TABLE temp SELECT * FROM $table just create table, don't pull data from table temp try // make sure all info provided if (($test1 == "test1" && $test2 == "test2") || $table == "") echo "Try again - enter what you need to enter."; else { $result = @mysql_query("CREATE TEMPORARY TABLE temp SELECT * FROM $table"); if (!$result) { exit("<p> Error performing query LINE 29" . mysql_error() . "</p>"); } $result = mysql_query('SELECT * FROM temp'); echo "before delete \n<pre>\n"; WHILE ($row = mysql_fetch_array($result)) { echo "row "; print_r($row); } echo '</pre>'; $sql = "DELETE FROM temp WHERE animal != $test1 AND transport != $test2"; $result = mysql_query('SELECT * FROM temp'); echo "after delete \n<pre>\n"; WHILE ($row = mysql_fetch_array($result)) { echo "row "; print_r($row); } echo '</pre>'; } Link to comment https://forums.phpfreaks.com/topic/95999-copy-table-content-and-structure/#findComment-492423 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.