Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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