У меня есть ошибка в mysqli_num_rows()ожидает, что параметр 1 будет находиться в mysqli_result bool, заданном в..
mysqli_num_rows() ожидает,что параметр 1 будет находиться в mysqli_result, bool задан в
$search <hr size="1"><br>"; $con=mysqli_connect("localhost","root","","search"); mysqli_select_db($con,"search"); //if($con) //echo"connection success"; //else //if(!$con) //echo"connection failed"; $search_exploded = explode (" ", $search); foreach($search_exploded as $search_each) { $x++; if($x==1) $construct .="keywords LIKE '%$search_each%'"; else $construct .="AND keywords LIKE '%$search_each%'"; } $construct ="SELECT * FROM searchengine WHERE $construct"; $run= mysqli_query($con,$construct); $foundnum= mysqli_num_rows($run); if ($foundnum==0) echo "Sorry, there are no matching result for $search.<br><br>1. Try more general words. for example: If you want to search 'how to create a website' then use general keyword like 'create' 'website'<br>2. Try different words with similar meaning<br>3. Please check your spelling"; else { echo "$foundnum results found !<p>"; while($runrows = mysqli_fetch_assoc($run)) { $title = $runrows ['title']; $desc = $runrows ['description']; $url = $runrows ['url']; echo " <a href="$url">$title</a><br> $desc<br> <a href="$url">$url</a></p><p> "; } } } } ?></p>
Что я уже пробовал:
<?php define("SITE_ADDR", "http://localhost/tutorials/search_engine"); include("./include.php"); $site_title = 'Simple Search Engine | HeyTuts.com tutorials'; ?> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <title><?php echo $site_title; ?></title> <!-- link to the stylesheets --> <link rel="stylesheet" type="text/css" href="./main.css"></link> </head> <body> <div id="wrapper"> <div id="top_header"> <div id="nav"> <a href="<?php echo SITE_ADDR;?>/new_entry.php">New Entry</a> </div> <div id="logo"> <h1><a href="<?php echo SITE_ADDR;?>">simple search engine</a></h1> </div> </div> <div id="main" class="shadow-box"><div id="content"> <center> <form action="" method="GET" name=""> <table> <tr> <td><input type="text" name="k" placeholder="Search for something" autocomplete="off"></td> <td><input type="submit" name="" value="Search" ></td> </tr> </table> </form> </center> <?php // CHECK TO SEE IF THE KEYWORDS WERE PROVIDED if (isset($_GET['k']) && $_GET['k'] != ''){ // save the keywords from the url $k = trim($_GET['k']); // create a base query and words string $query_string = "SELECT * FROM search_engine WHERE "; $display_words = ""; // seperate each of the keywords $keywords = explode(' ', $k); foreach($keywords as $word){ $query_string .= " keywords LIKE '%".$word."%' OR "; $display_words .= $word." "; } $query_string = substr($query_string, 0, strlen($query_string) - 3); // connect to the database $conn = mysqli_connect('localhost','root',"",'tutorials'); $query = mysqli_query($conn, $query_string); $result_count = mysqli_num_rows($query); // check to see if any results were returned if ($result_count > 0){ // display search result count to user echo '<br /><div class="right">'.$result_count.' results found</div>'; echo 'Your search for '.$display_words.' <hr /><br />'; echo '<table class="search">'; // display all the search results to the user while ($row = mysqli_fetch_assoc($query)){ echo '<tr> <td><h3><a href="'.$row['url'].'">'.$row['title'].'</a></h3></td> </tr> <tr> <td>'.$row['blurb'].'</td> </tr> <tr> <td>'.$row['url'].'</td> </tr>'; } echo '</table>'; } else echo 'No results found. Please search something else.'; } else echo ''; ?> </div></div> <div id="footer"> <div class="clear"></div> </div> </div> </body> </html>