. Advertisement .
..3..
. Advertisement .
..4..
While running my program, I get the ”warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in” error. It in line 31:
<pre>if(mysqli_num_rows($results) >= 1)</pre>
Then I have revised my code:
<pre>
<?php
//capture search term and remove spaces at its both ends if the is any
$searchTerm = trim($_GET['keyword']);
//check whether the name parsed is empty
if($searchTerm == "")
{
echo "Enter the name/brand of what you're looking for.";
exit();
}
//database connection info
$host = "localhost";
$db_name = "sookehhh_shopsy_db";
$username = "sookehhh_shopsy";
$password = "xxxx";
//connecting to server and creating link to database
$link = mysqli_connect($host, $username, $password, $db_name) or die('Could not connect: ' . mysqli_connect_error());
//MYSQL search statement
$query = "SELECT * FROM sookehhh_shopsy_db WHERE name LIKE '%" . mysqli_real_escape_string($link, $searchTerm) . "%'";
// original query$query = "SELECT * FROM sookehhh_shopsy_db WHERE name LIKE '%$searchTerm%'";
$results = mysqli_query($link, $query);
//added suggestion below - not sure if correct place?
if (!$result) {
die(mysqli_error($link));
}
/* check whethere there were matching records in the table
by counting the number of results returned */
if(mysqli_num_rows($results) >= 1)
{
$output = "";
while($row = mysqli_fetch_array($results))
{
$output .= "Product Name: " . $row['name'] . "<br />";
$output .= "Price: " . $row['price'] . "<br />";
}
echo $output;
}
else
echo "There was no matching record for that item " . $searchTerm;
?>
</pre>
But its not work. Can you give me some solutions?