etsted Posted February 3, 2014 Share Posted February 3, 2014 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 More sharing options...
Mudsaf Posted February 3, 2014 Share Posted February 3, 2014 (edited) $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 February 3, 2014 by Mudsaf Link to comment Share on other sites More sharing options...
etsted Posted February 3, 2014 Author Share Posted February 3, 2014 the error message: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given Link to comment Share on other sites More sharing options...
etsted Posted February 3, 2014 Author Share Posted February 3, 2014 Mudsaf, it didnt work :S Link to comment Share on other sites More sharing options...
Ingolme Posted February 3, 2014 Share Posted February 3, 2014 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. Link to comment Share on other sites More sharing options...
etsted Posted February 3, 2014 Author Share Posted February 3, 2014 yeah that worked. Thank you man... Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now