Re: php/mySQL search/mysql_num_rows() error
- From: "J.O. Aho" <user@xxxxxxxxxxx>
- Date: Mon, 12 Jun 2006 21:43:52 +0200
Chris wrote:
I'm working on some search engine code from devpapers.com and keep coming up against an error when testing.
This is the error I get:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in c:\Inetpub\wwwroot\TMP8j9vfrf3s.php on line 36
Couldn't execute query
as the result from the mysql_query() can be a resource or FALSE, and in your case it's a FALSE that is returned and not a resource, which leads mysql_num_row() to output an error.
-------------------------------
These are lines 33 through 36:
$query = "SELECT * FROM links WHERE pageURL LIKE \"%$trimm%\" OR pageDesc LIKE \"%$trimm%\" OR pageTitle LIKE \"%$trimm%\" ORDER BY pageLink DESC" ;
// Execute the query to get number of rows that contain search keywords
$numresults = mysql_query($query);
$row_num_links_main = mysql_num_rows($numresults);
-----------------------------------
I'm guessing it's a simple syntax error and I just can't see it after looking at it so long, so maybe a different set of eyes will see it.
I suggest you do a small change to your code
//SQL queries uses single quotes to enclose strings
$query = "SELECT * FROM links WHERE pageURL LIKE '%$trimm%' OR
pageDesc LIKE '%$trimm%' OR pageTitle LIKE '%$trimm%' ORDER BY pageLink
DESC" ;
// Execute the query to get number of rows that contain search keywords
$numresults = mysql_query($query);
if($numresults) {
//$numresults is a resource!!!
$row_num_links_main = mysql_num_rows($numresults);
} else {
//$numresults is false
echo "Query: $query<br>\n".mysql_errno().": ".mysql_error()."<br>\n";
exit;
}
This way you see what is wrong with your query or if you have connection problems. When the page is finished, you may want to store this in a error log file instead of outputting it to the web page.
//Aho
.
- Follow-Ups:
- Re: php/mySQL search/mysql_num_rows() error
- From: Chris
- Re: php/mySQL search/mysql_num_rows() error
- References:
- php/mySQL search/mysql_num_rows() error
- From: Chris
- php/mySQL search/mysql_num_rows() error
- Prev by Date: php/mySQL search/mysql_num_rows() error
- Next by Date: Re: php/mySQL search/mysql_num_rows() error
- Previous by thread: php/mySQL search/mysql_num_rows() error
- Next by thread: Re: php/mySQL search/mysql_num_rows() error
- Index(es):
Relevant Pages
|
|