Hi, need some help with the a php code i made to a search engine, i get a error: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/eoopoedt/public_html/sok/search.php on line 49

Can some one fiks my code, and give me the right code:

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

if (!$button)
echo "Søket samsvarer ikke med noen dokumenter. <br>
Prøv igjen senere.";
else
{
	if (strlen($search) <=0) 
	echo "Søket samsvarer ikke med noen dokumenter. <br>
Prøv igjen senere.";
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 AND url AND title LIKE '%$search_each%'";
		else
		$constuct .= "OR keywords AND url AND title LIKE'%$search%'";
	}
	$constryct = "SELECT * FROM søkemotor WHERE $construct";
	$run = mysql_query($construct);
	$foundnum = mysql_num_rows($run);
	if ($foundnum == 0)
	echo "Ingen treff på søkeordet ditt.";
	else
	{
		echo "$foundnum resultater funnet på søkeordet ditt";
		while ($runrows = mysql_fetch_assoc($run))
		{
			$title = $runrows['title'];
			$desc = $runrows ['description'];
			$url = $runrows ['url'];
			echo "
			<b>$title</b><br>
			$desc<br>
			<a herf ='$url'>$url</a><p>";
		}
	}
}
}
		
?>

Have you tried reading the sticky at the top of this forum? It sounds like your problem is very similar to the one listed there, and your answer might be in that thread.

Member Avatar for diafol
$constryct = "SELECT * FROM søkemotor WHERE $construct";
$run = mysql_query($construct);
$foundnum = mysql_num_rows($run);

Should be:

$construct = "SELECT * FROM søkemotor WHERE $construct";
$run = mysql_query($construct);
$foundnum = mysql_num_rows($run);

I still get the error :S

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/eoopoedt/public_html/sok/search.php on line 58

Member Avatar for diafol
SELECT * FROM `søkemotor` WHERE $construct

AND

$construct .="keywords AND url AND title LIKE '%$search_each%'";
		else
		$constuct .= "OR keywords AND url AND title LIKE'%$search%'";

doesn't make sense

perhaps:

if ($x=1){
	$construct .="keywords LIKE '%$search_each%' AND url LIKE '%$search_each%' AND title LIKE '%$search_each%'";
}else{
	$constuct .= "keywords LIKE '%$search_each%' OR url LIKE '%$search_each%' OR title LIKE'%$search%'";
}
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.