Jump to content

mysql_num_rows


eryx

Recommended Posts

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 X
My host company has a linx server running MySQL client version: 4.1.10

I also tried the

mysql_numrows(); and
mysql_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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.