Another mysql_num_rows(): error

Reply

Join Date: Jun 2005
Posts: 4
Reputation: dantrujillo is an unknown quantity at this point 
Solved Threads: 0
dantrujillo dantrujillo is offline Offline
Newbie Poster

Another mysql_num_rows(): error

 
0
  #1
Jun 16th, 2005
I am getting the following error:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/champion/public_html/search.php on line 34 when doing a search for text in a description or product name. The error only happens when I do a search for multiple words.

Here is the code:

if ( $st ) {

include("admin/include/db.php");
mysql_select_db ("dbname");

# remove multiple spaces
$st = ereg_replace(" +"," ",$st);
# remove unwanted spaces and split words
if ( strstr($st,",") ) {
$st = str_replace(" ", "", $st);
$w_ar = split(",",$st);
} else {
$w_ar = split(" ",$st);
}
$ac = count($w_ar);
# construct search pattern
if ( $ac > 0 ) {
for ( $i=0; $i<$ac; $i++ ) {
if ( $i>0 && $i<$ac ) $cmp_str .= " ";
$cmp_str .= "$w_ar[$i]";
if ( $ac == 1 ) {
$cmp_str .= "*"; # add wildcard
$bmode = "IN BOOLEAN MODE";
}
}
}

$query = "SELECT *,MATCH(pdescription,pname,pclass,pgroup,manu) AGAINST ('$cmp_str' $bmode) AS score
FROM products WHERE MATCH(pdescription,pname,pclass,pgroup,manu) AGAINST ('$cmp_str' $bmode)";

$result = mysql_query($query);
$num_result = mysql_num_rows($result);


if ( $num_result == 0 ) {
$html_out = "<tr><td colspan=6>No results were found for $st.</td></tr>";
} else {
$count = 1;
$html_out .= "<tr><td colspan=6>&nbsp;Search found $num_result matches for <b>$st</b><br><br></td></tr>\n";
for ( $i=0; $i<$num_result; $i++ ) {
$row = mysql_fetch_object($result);
if ( $count == 1 ) { $html_out .= "<tr>"; }
$html_out .= "<td align=center width=160 class=bodytext valign=top><a href=products/$row->pclass/$row->prod_id><img src=images/products/sm_$row->pimage";
if ( $row->filename == "" ) $html_out .= ""; else $html_out .= $row->filename;
$html_out .= " border=0></a><br><b>$row->pname</b></td>\n";
$html_out .= "<td width=30><img src=/images/clear.gif width=30 height=1></td>\n";
if ( $count == 3 ) { $html_out .= "</tr><tr><td colspan=6><br></td></tr>"; $count = 0;}
$count++;
}
}
$html_out .= "<tr><td align=center><br><br><a href=javascript:history.back()><font color=black>back</font></a><br></td></tr>";



Any ideas?
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 354
Reputation: Troy is an unknown quantity at this point 
Solved Threads: 5
Troy's Avatar
Troy Troy is offline Offline
Posting Whiz

Re: Another mysql_num_rows(): error

 
0
  #2
Jun 16th, 2005
This may seem too obvious, but the problem is that $result is not a valid MySQL resource. So why is that? Since your other queries work, we have to assume your connection is good. So the almost sure candidate is your query. Something is wrong with your query. Try changing your code to this:

[PHP]
if (!$result = mysql_query($query)) {
die(mysql_error());
}
$num_result = mysql_num_rows($result);
[/PHP]
This should print an error message that indicates what is wrong with the query.

Refer to http://us3.php.net/manual/en/function.mysql-error.php

Another thing I like to do when I'm having trouble with a query is run it directly against the database rather than in a PHP page. Do you have access to run the query directly against the database? For example, command line or phpMyAdmin? These tools give you nice feedback telling you what's wrong.
Troy Wolf is the author of SnippetEdit. "Website editing as easy as it gets." IX Web Hosting
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 4
Reputation: dantrujillo is an unknown quantity at this point 
Solved Threads: 0
dantrujillo dantrujillo is offline Offline
Newbie Poster

Re: Another mysql_num_rows(): error

 
0
  #3
Jun 16th, 2005
It gives me the following:

Can't find FULLTEXT index matching the column list

which according to the the error handling list is:

Error: 1191 SQLSTATE: HY000 (ER_FT_MATCHING_KEY_NOT_FOUND)

Message: Can't find FULLTEXT index matching the column list


I'm just drawing a blank. I think I've just looked at it too long......

Thank you! You've given me another avenue to investigate.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 354
Reputation: Troy is an unknown quantity at this point 
Solved Threads: 5
Troy's Avatar
Troy Troy is offline Offline
Posting Whiz

Re: Another mysql_num_rows(): error

 
0
  #4
Jun 16th, 2005
I don't have much experience setting up fulltext indexes, but I think your issue is that not all (or any?) of the columns you are passing to the MATCH() function have fulltext indexes setup on them.
Troy Wolf is the author of SnippetEdit. "Website editing as easy as it gets." IX Web Hosting
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 4
Reputation: dantrujillo is an unknown quantity at this point 
Solved Threads: 0
dantrujillo dantrujillo is offline Offline
Newbie Poster

Re: Another mysql_num_rows(): error

 
0
  #5
Jun 16th, 2005
I will check that too. Thank you!
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 4
Reputation: dantrujillo is an unknown quantity at this point 
Solved Threads: 0
dantrujillo dantrujillo is offline Offline
Newbie Poster

Re: Another mysql_num_rows(): error

 
0
  #6
Jun 17th, 2005
I changed the index of the columns to FULLTEXT and only perform the MATCH() on the pdescription column. It works great if I only use 1 column. If I add any other column to the MATCH(), I get the mysql_num_rows() error.

So, has anyone dealth with tokenizing the words of the search to see if there is a match in any of the columns for the token and not the word phrase?

Would that be the next thing to try?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC