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> 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?