logo-dw

Go Back   Dreamweaver Club Forums > Hand Coders Forum > PHP
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
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
Old 02-27-2012, 11:10 PM   #2
gentleone
gentleone's Avatar
 
Join Date: Nov 2009
Location: Rhodes, Greece
Posts: 2,837
Default

This has nothing to do with Spry. Moved to the PHP board.
__________________
www.gentlemedia.nl
gentleone is offline   Reply With Quote
Old 02-27-2012, 11:14 PM   #3
sydesign
 
Join Date: Jan 2011
Posts: 41
Default

Quote:
Originally Posted by gentleone View Post
This has nothing to do with Spry. Moved to the PHP board.
ah yes sorry I think I was distracted ... thank you.
sydesign is offline   Reply With Quote
Old 02-28-2012, 01:29 AM   #4
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,170
Default

is this the line if ($numrows > 0?

just before it, add line echo $numrows: see what is returning
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is offline   Reply With Quote
Old 02-28-2012, 05:42 AM   #5
sydesign
 
Join Date: Jan 2011
Posts: 41
Default

like this?

PHP Code:
$query mysql_query($query);
        
$numrows mysql_num_rows($query);
        
        echo 
$numrows;
        
        if (
$numrows 0){ 
i still get the same result and error..

which is kind of interesting now because it still says on line 228 but theres nothing on line 228 anymore
sydesign is offline   Reply With Quote
Old 02-28-2012, 07:31 AM   #6
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,170
Default

yes but its not a cure, its to echo out what is being returned as $numrows
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is offline   Reply With Quote
Old 02-28-2012, 06:35 PM   #7
sydesign
 
Join Date: Jan 2011
Posts: 41
Default

yea i know. i just meant that i didn't see anything different come up. i didn't see it echo any results. does this mean theres a problem with the code? or the database?

Im not sure..
sydesign is offline   Reply With Quote
Old 02-29-2012, 02:30 AM   #8
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,170
Default

i would guess code as its not returning row count
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is offline   Reply With Quote
Old 02-29-2012, 02:35 AM   #9
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,170
Default

for one put ypour connect and select database before the select query
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 04:48 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com