|
-
Mar 19th, 2006, 06:09 PM
#1
Thread Starter
Fanatic Member
[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
-
Mar 19th, 2006, 10:41 PM
#2
Thread Starter
Fanatic Member
Re: MYSQL Num Rows Problem - Help Needed
-
Mar 19th, 2006, 10:58 PM
#3
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();
}
Last edited by penagate; Mar 19th, 2006 at 11:02 PM.
-
Mar 19th, 2006, 11:01 PM
#4
Lively Member
Re: MYSQL Num Rows Problem - Help Needed
 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);
-
Mar 19th, 2006, 11:41 PM
#5
<?="Moderator"?>
Re: MYSQL Num Rows Problem - Help Needed
 Originally Posted by penagate
Please don't bump your posts after such a short time.
Got there before me 
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.
-
Mar 20th, 2006, 10:03 PM
#6
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);
-
Mar 20th, 2006, 11:19 PM
#7
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.
-
Mar 21st, 2006, 02:04 AM
#8
Re: MYSQL Num Rows Problem - Help Needed
When in doubt, refer to the manual! 
 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()
-
Mar 21st, 2006, 02:38 AM
#9
Re: MYSQL Num Rows Problem - Help Needed
who ever reads a manual these days!!
-
Mar 21st, 2006, 03:47 AM
#10
<?="Moderator"?>
Re: MYSQL Num Rows Problem - Help Needed
 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.
 Originally Posted by lintz
who ever reads a manual these days!! 
Like my lecturer keeps telling us RTFM
-
Mar 21st, 2006, 06:20 AM
#11
Re: MYSQL Num Rows Problem - Help Needed
LMAO
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|