Jump to content

Recommended Posts

This is part of my code for a simple search function. It works for my test site on wampserver;

						//sql fulltext statement against words/phrase user enters
					$sql = "SELECT *, MATCH(company_name, search_data) AGAINST('%$_GET[searchterms]%') AS score FROM
					adverts WHERE MATCH(company_name, search_data) AGAINST('%$_GET[searchterms]%') LIMIT 0, 500";
									   
					$result = mysql_query($sql);

					//display an error if the query returns no results
					if (mysql_num_rows($result) < 1 && strlen($searchTerms) > 3 && strlen($searchTerms) < 50) {
         					echo "<font color=\"red\">No results found for <strong>{$searchTerms}</strong></font>.";
						$flag = "NOTOK";
      					}

 

However, when I host it live and try to use it I get this error message;

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/overone1/public_html/search.php on line 70

 

Line 70 is if (mysql_num_rows($result) < 1 && strlen($searchTerms) > 3 && strlen($searchTerms) < 50) {

 

Please could someone explain what I have done wrong here and what the best way to fix it is?

 

Thank you

 

Link to comment
https://forums.phpfreaks.com/topic/203982-what-does-this-error-message-mean/
Share on other sites

That error will occur when you have a syntax error in the mysql query, do this:

<?php
$sql = "SELECT *, MATCH(company_name, search_data) AGAINST('%$_GET[searchterms]%') AS score FROM
adverts WHERE MATCH(company_name, search_data) AGAINST('%$_GET[searchterms]%') LIMIT 0, 500";
$result = mysql_query($sql) or die("Problem with the query: $sql<br>" . mysql_error());
?>

 

and see what is displayed. The error should  point you in the right direction.

 

Ken

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.