0

This is some PHP search code with some mistake. $run gives nothing where $run = mysql_query($construct); It gives: Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\xampp\search\search2.php on line 39
No results found.

<?php

//get data
$button = $_GET['submit'];
$search = $_GET['search'];

if(!$button)
	echo "You didn't submit a keyword.";
else
{
	if (strlen($search)<=3)
		echo "Search term too short.";
	else
	{
		echo "You searched for <b>$search</b> <hr size='1'>";
		
		//connect to our database
	mysql_connect("localhost","root","");
	mysql_select_db("usertable");

		//explode our search term
		$search_exploded = explode(" ",$search);
	
			foreach($search_exploded as $search_each)
			{
				//construct query
				$x++;
				if ($x==1)
					$construct .= "keyword LIKE '%$search_each%'";
				else
					$construct .= "OR keywords LIKE '%$search_each%'";
			}
		
		
		$construct = "SELECT * FROM search WHERE '$construct'";
		$run = mysql_query($construct);
		echo $run;
		
		$foundnum = mysql_num_rows($run);
		
		if ($foundnum==0)
			echo "No results found.";
		else
		{
			echo "$foundnum results found!<p>";
		}

	}
}

?>

Edited by george61: n/a

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by george61
0

Try losing the the single quotes around $construct. Instead you want to prepend the SELECT statement right?

$construct = "SELECT * FROM search WHERE $construct";

Edited by madCoder: n/a

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.