0

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>";
			}
		}
		
	}
}
?>
4
Contributors
6
Replies
7
Views
6 Years
Discussion Span
Last Post by jtreminio
0

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);
0

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.

0

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

0

): 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

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.