Jump to content

error


etsted
 Share

Recommended Posts

this script keep returning warning mysqli_num_rows expect paramter 1 to be a result boolean given. Why?

 

<html>
<body>
<h1>search engine</h1>
<form action="search.php" method="get">
<input type="text" name="k" size='50' />
<input type="submit" name="submit" value='Search' />
</form>
<hr />
<?php
include "connect.php";
$k = $_GET['k'];
$terms = explode(".", $k);
$query = "SELECT * FROM users WHERE ";
foreach($terms as $each) {
$i++;
if($i == 1) {
$query .= "keywords LIKE '%$each%' ";
} else {
$query .= "OR keywords LIKE '%$each%' ";
}
}
$query = mysqli_query($con, $query);
$numrows = mysqli_num_rows($query);
if($numrows > 0)
{
while($row = mysqli_fetch_array($query)) {
$id = $row['id'];
$title = $row['title'];
$description = $row['description'];
$keywords = $row['keywords'];
$link = $row['link'];
if($k == "") {
echo "";
} else {
echo "<h2><a href='$link'>$title</a></h2>
$description";
}
}
}
else
{
echo "no result on $k";
}
?>
</body>
</html>
Link to comment
Share on other sites

        $query .= "OR keywords LIKE '%$each%' ";    }}   $query = mysqli_query($con, $query);$numrows = mysqli_num_rows($query);

I think you should do it like this

        $query .= "OR keywords LIKE '%$each%' ";    }}   $result = mysqli_query($con, $query);$numrows = mysqli_num_rows($result);
Edited by Mudsaf
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...