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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.