eryx Posted January 26, 2007 Share Posted January 26, 2007 Here is my code [code]// Connect to server and select databse.$link = mysql_connect("$host", "$username", "$password");mysql_select_db("$db_name", $link);$result = mysql_query("SELECT * FROM $tbl_name", $link);$num_rows = mysql_num_rows($result);echo "$num_rows Rows\n";[/code]I get this error message[quote]Warning: mysql_num_rows: supplied argument is not a valid MySQL result resource in -----myURL----[/quote]took this code from [url=http://www.php.net/mysql_num_rows]http://www.php.net/mysql_num_rows[/url]I am new to PHP but this just does not make sense to me. I am working on a mac OS XMy host company has a linx server running MySQL client version: 4.1.10I also tried the mysql_numrows(); andmysql_fetch_row();same result, am I missing something. Thank for any insight. Link to comment https://forums.phpfreaks.com/topic/35877-mysql_num_rows/ Share on other sites More sharing options...
ballhogjoni Posted January 26, 2007 Share Posted January 26, 2007 is there anything in your database? Link to comment https://forums.phpfreaks.com/topic/35877-mysql_num_rows/#findComment-170101 Share on other sites More sharing options...
Jessica Posted January 26, 2007 Share Posted January 26, 2007 1. You don't need quotes around variables.2. try $result = mysql_query("SELECT * FROM $tbl_name", $link) OR die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/35877-mysql_num_rows/#findComment-170110 Share on other sites More sharing options...
ballhogjoni Posted January 26, 2007 Share Posted January 26, 2007 I was gonna say to try this[code]<?php $sql = "SELECT * FROM foo"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { // it is now safe to use your result in here. } else { echo "No records found"; } } else { echo "Query failed ".mysql_error()."<br />$sql"; }?>[/code]at least it will help you understand what you are missing Link to comment https://forums.phpfreaks.com/topic/35877-mysql_num_rows/#findComment-170112 Share on other sites More sharing options...
eryx Posted January 26, 2007 Author Share Posted January 26, 2007 Thanks jesirose and ballhogjoniyour posts were very helpful, I am not sure exactly why they worked but like I said I am new at this. I have a lot more to learn, thanks for getting me over this hump. Link to comment https://forums.phpfreaks.com/topic/35877-mysql_num_rows/#findComment-170116 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.