conker87 Posted September 30, 2007 Share Posted September 30, 2007 I'm just wondering how to get rid of this warning: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/conker87/public_html/<page> on line <line> If the number of rows is equal to zero. I've tried inserting this: if (mysql_num_rows($result) == 0) { $rowcount = 0; } else { $rowcount = mysql_num_rows($result); } But it still shows. Any ideas? Link to comment https://forums.phpfreaks.com/topic/71270-solved-mysql_num_rows-warning/ Share on other sites More sharing options...
pocobueno1388 Posted September 30, 2007 Share Posted September 30, 2007 It means that there is something wrong with your query. Put a die statement at the end of it. EX. $result = mysql_query($query)or die(mysql_error()); That will tell you what went wrong. Link to comment https://forums.phpfreaks.com/topic/71270-solved-mysql_num_rows-warning/#findComment-358480 Share on other sites More sharing options...
NoSalt Posted September 30, 2007 Share Posted September 30, 2007 You could try my favorite "tertiary" operator: $rowcount = (mysql_num_rows($result)) ? (mysql_num_rows($result)) : '0'; my_sql_numrows will return either the number of rows or a 'false'. So if it returns a false you assign $rowcount a '0' if mysql_num_rows returns anything else, you can assign $rowcount that number. In you code you are using mysql_num_rows as if it exists, but if it has no rows (i.e., a 'false' return) then it will not exist. Link to comment https://forums.phpfreaks.com/topic/71270-solved-mysql_num_rows-warning/#findComment-358484 Share on other sites More sharing options...
conker87 Posted September 30, 2007 Author Share Posted September 30, 2007 It means that there is something wrong with your query. Put a die statement at the end of it. EX. $result = mysql_query($query)or die(mysql_error()); That will tell you what went wrong. I noticed that I'd spelt the table slightly wrong. Thanks anyway. Link to comment https://forums.phpfreaks.com/topic/71270-solved-mysql_num_rows-warning/#findComment-358489 Share on other sites More sharing options...
BlueSkyIS Posted September 30, 2007 Share Posted September 30, 2007 for future reference, it'll be easier to "notice" if you let MySQL tell you what the problem is using or die(mysql_error()); $result = mysql_query($query) or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/71270-solved-mysql_num_rows-warning/#findComment-358492 Share on other sites More sharing options...
conker87 Posted September 30, 2007 Author Share Posted September 30, 2007 I copied it from your example above, ta Link to comment https://forums.phpfreaks.com/topic/71270-solved-mysql_num_rows-warning/#findComment-358509 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.