This question already has an answer here:
- mysql_fetch_array()/mysql_fetch_assoc()/mysql_fetch_row()/mysql_num_rows etc… expects parameter 1 to be resource or result 32 answers
- How to get MySQLi error information in different environments? / mysqli_fetch_assoc() expects parameter 1 to be mysqli_result 1 answer
- Reference - What does this error mean in PHP? 34 answers
I created this code for searching multiple words at once, but my code doesn't work. Most of errors that appeared along the way I corrected by myself, but with this does not work.
When I hit the search button, it gives me this error:
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\XAMPP\htdocs\test\search.php on line 26
Here is my code:
<?php
$host = 'localhost';
$user = 'root';
$password = '';
$database = 'dictionary';
$connect = new mysqli ($host, $user, $password, $database);
if (isset($_GET['search'])) {
$condition = '';
$query = explode(" ", $_GET['search']);
foreach ($query as $text)
{
$condition .= "hieroglyphs LIKE '%".mysqli_real_escape_string($connect, $text)."%' OR";
}
$condition = substr($condition, 0, -4);
$sql_query = "SELECT hieroglyphs, meaning FROM test_dictionary WHERE " . $condition;
$result = mysqli_query($connect, $sql_query);
if (mysqli_num_rows($result) > 0)
{
echo "<table><tr><th>Hieroglyphs</th><th>Meaning</th></tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr><td>".$row["hieroglyphs"]."</td><td>".$row["meaning"]."</td></tr>";
}
echo "</table>";
} else {
echo "0 results";
}
}
$connect->close();
?>
How to correct this error? Thank you in advance.