[RESOLVED] MYSQL Num Rows Problem - Help Needed
why do i get an error when i run this code?
PHP Code:
$sql = "SELECT * FROM tbl_Quotes";
$rs = mysql_query($sql);
$numrows = mysql_num_rows($rs);
the error is below
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource
thanks
Re: MYSQL Num Rows Problem - Help Needed
Re: MYSQL Num Rows Problem - Help Needed
Please don't bump your posts after such a short time.
You can dump the last error message generated by MySQL by using the mysql_error() function.
PHP Code:
$sql = "SELECT * FROM tbl_Quotes";
$rs = mysql_query($sql);
if (mysql_errno()) {
echo mysql_error();
}
Re: MYSQL Num Rows Problem - Help Needed
Quote:
Originally Posted by modpluz
why do i get an error when i run this code?
PHP Code:
$sql = "SELECT * FROM tbl_Quotes";
$rs = mysql_query($sql);
$numrows = mysql_num_rows($rs);
the error is below
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource
thanks
use this one.
PHP Code:
$sql = "SELECT * FROM tbl_Quotes";
$rs = mysql_query($sql) or die(mysql_error());
$numrows = mysql_num_rows($rs);
Re: MYSQL Num Rows Problem - Help Needed
Quote:
Originally Posted by penagate
Please don't bump your posts after such a short time.
Got there before me :wave:
uttam die should be only for debugging, as it will stop the execute of the script, for live scripts use penagates method of displaying MySQL errors.
Re: MYSQL Num Rows Problem - Help Needed
it errors because that function does not exist it is:
mysql_numrows() not mysql_num_rows
so...
Code:
$row_count = mysql_numrows($result);
Re: MYSQL Num Rows Problem - Help Needed
the182guy, I use mysql_num_rows all the time to find out how many records have been returned from my query without it ever displaying an error.
Re: MYSQL Num Rows Problem - Help Needed
When in doubt, refer to the manual! :)
Quote:
Originally Posted by [url=php.net/mysql_num_rows]mysql_num_rows[/url]
Note: For downward compatibility, the following deprecated alias may be used: mysql_numrows()
Re: MYSQL Num Rows Problem - Help Needed
who ever reads a manual these days!! :D
Re: MYSQL Num Rows Problem - Help Needed
Quote:
Originally Posted by lintz
the182guy, I use mysql_num_rows all the time to find out how many records have been returned from my query without it ever displaying an error.
If this would try the error message he would have seen first would be, Fatal error: Call to undefined function.
It's not working because their is a problem with his query. This is not returning a valid resource that mysql_num_rows requires. Check with msql_error is your best bet.
Quote:
Originally Posted by lintz
who ever reads a manual these days!! :D
Like my lecturer keeps telling us RTFM
Re: MYSQL Num Rows Problem - Help Needed