View Single Post
Old 02-27-2012, 10:56 PM   #1
sydesign
 
Join Date: Jan 2011
Posts: 41
Default mysql_num_rows() error

I am trying to create a search engine of sorts on a site for my client. the php code is

PHP Code:
    <?php
        $k 
$_GET ['k'];
        
$terms explode(" "$k);        
        
$query "SELECT * FROM search WHERE ";

        foreach (
$terms as $each){
            
$i++;

            if (
$i == 1)
                
$query .= "keywords LIKE '%$each%' ";
            else
                
$query .= "OR keywords LIKE '%$each%' ";
            
        }
        
        
// connect
        
mysql_connect("localhost""root""root");
        
mysql_select_db("searchengine");
        
        
$query mysql_query($query);
        
$numrows mysql_num_rows($query);
        if (
$numrows 0){
            
            while (
$rows mysql_fetch_assoc($query)){
                
$title $rows['title'];
                
$description $rows['description'];
                
$keywords $rows['keywords'];
                
$link $rows['link'];
            
                echo 
"<h2><a href='$link'>$title</a></h2>
                
$description<br /><br />";
            }
            
        }
        else
            echo 
"No results found for \"<b>$k</b>\"";
        
        
//disconnect
        
mysql_close();
    
?>
when i submit this form:
PHP Code:
<form method="get" action="results.php">
    <input type="text" name="k" size="30" value="<?php echo $_GET['k']; ?>"/>
    <input type="submit" value="Search" />
</form>
i get this error:

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in ***.php on line 228

I've been searching around for why this happens and i haven't found a reason that helps me. This is my first time teaching myself and trying to learn phpmyadmin and mysql databases so i don't know if maybe I'm doing something wrong...

thank you so much for any help you can offer!
sydesign is offline   Reply With Quote