Jump to content

copy table content and structure


Southern Belle

Recommended Posts

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?

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>';
} 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.