Jump to content
Sign in to follow this  


Recommended Posts

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


<h1>search engine</h1>
<form action="search.php" method="get">
<input type="text" name="k" size='50' />
<input type="submit" name="submit" value='Search' />
<hr />
include "connect.php";
$k = $_GET['k'];
$terms = explode(".", $k);
$query = "SELECT * FROM users WHERE ";
foreach($terms as $each) {
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>
echo "no result on $k";

Share this post

Link to post
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

Share this post

Link to post
Share on other sites

The message means that your query failed. To find out why it failed, use the mysqli_error() function.


You've forgotten to initialize $i to a value before your first loop, which might also be causing the problem.

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Create New...