Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mysql_num_rows 2

Status
Not open for further replies.

bccamp

Technical User
Jan 20, 2005
69
I'm having a problem getting the mysql_num_rows to deliver a result. I keep getting the error "mysql_num_rows(): supplied argument is not a valid MySQl result resource in .....

1) is there a limit to what mysql_num_rows() can discern?
2) are there limits to what my $query can have?

ex.
$query = "select NUM from db where CATEGORY = $click"; //$click is passed from previous page, it is set to NULL if //no value
$result1 = mysql_query($query);
$num1=mysql_num_rows($result1);

results in the error. The db has about 3000 listings. Is my syntax wrong?

Thanks
 
select NUM from db where CATEGORY = NULL" is not valid sql, the database is probably returning an error rather than a result set.
 
are you sure the query gives you some row?

modify the $result1 line with:

$result1 = mysql_query($query) or die("MySQL Error:" . mysql_error());

cheers.
 
Along the same lines, if $click is a string then it needs to be quoted, otherwise the database will think you're referencing a column rather than a value.
 
You probably want to write your query as
Code:
$query = "select `NUM` from db where `CATEGORY` = '$click'";
Use the back ticks around CATAGORY and NUM just in case MySQL thinks they are reserved words.

Ken
 
The punctuation always gets me! Thanks guys. Been stuck on this for a while. The error occurred on the CATEGORY = $click. Changing to CATEGORY = '$click' fixed the problem. Thanks for all the responses.

Barry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top