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. Quote Link to comment Share on other sites More sharing options...
ballhogjoni Posted January 26, 2007 Share Posted January 26, 2007 is there anything in your database? Quote Link to comment 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()); Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.