Hi, i am making a search engine in php and i just get a warning that i cant understand: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/eoopoedt/public_html/sok/search.php on line 27 See it your self: http://eoop.org/sok/

My code:

<?php
$button = $_GET['submit'];
$search = $_GET['search'];

if (!$button)
echo "søket samsvarer ikke med noen dokumenter. <br>";
else 
{
	if (strlen ($search) <=0)
	echo " Søket samsvarer ikke med noen dokumenter. <br>";
	else
	{
		echo "Søkeordet ditt: <b>$search</b> <hr size '1'>";
		mysql_connect("localhost","eoopoedt","200152007w");
		mysql_select_db("eoop");
		$search_exploded = explode(" ",$search);
		foreach($search_exploded as $search_each)
		{
			$x++;
			if ($x = 1)
			$construct .= "keywords LIKE '%search_each%'";
			else
			$construct .= "OR keywords LIKE '%search_each%'";
		}
		$construct = "SELECT * FROM søkemotor WHERE $construct";
		$run = mysql_query($construct);
		$num_rows = mysql_num_rows($run);
		if ($num_rows==0)
		echo "Ingen treff på søkeordet ditt.";
		else 
		{
			echo "$foundnum resultater på ditt søkeordt";
			while ($runrows = mysql_fetch_assoc($run))
			{
				$title = $runrows['title'];
				$desc = $runrows['description'];
				$url = $runrows['url'];
				
				echo"
				<tb>$title </b><br>
				$desc<br>
				<a herf = '$url'>$url</a>";
			}
		}
		
	}
}
?>

Recommended Answers

All 6 Replies

my guess is your mysql query is invalid. Try doing an echo on the query and test the query in mysql to see if it runs. Also try putting the $construct above the for loop

$construct = "SELECT * FROM søkemotor WHERE ";//note the space at the end
foreach($search_exploded as $search_each)
		{
			$x++;
			if ($x = 1)
			$construct .= "keywords LIKE '%search_each%'";
			else
			$construct .= "OR keywords LIKE '%search_each%'";
		}
$run = mysql_query($construct);

You're not instantiating $x before adding to it on line 19.

You're not instantiating $construct before adding to it on line 21 and 23.

You're also not using

search_each

in the SQL since it's not printed as a variable:

%search_each%

should be

%{$search_each}%

on lines 21 and 23.

My error is in line 27. Evrey thing else is fine, my error:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/eoopoedt/public_html/sok/search.php on line 27

): supplied argument is not a valid MySQL

means that the query is probably invalid in mysql. you're concatenating $construct to an unassigned variable then assigning is after to the query which will make the query invalid, which is why I asked you to put the $construct before the for loop

My error is in line 27. Evrey thing else is fine, my error:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/eoopoedt/public_html/sok/search.php on line 27

You're not paying attention.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.