RSS Forums RSS
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 3666 | Replies: 5
Join Date: Jun 2005
Posts: 4
Reputation: dantrujillo is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
dantrujillo dantrujillo is offline Offline
Newbie Poster

Another mysql_num_rows(): error

  #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?
AddThis Social Bookmark Button
Reply With Quote  

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 12:15 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC