Hey again. This seems really simple, but I am not getting the integer value I want. Instead, I get "ressource id #12" if I echo $count[0], and just "object" if I echo $countdata[0]. Why wont it work!?

$count[0] = mysql_query("SELECT COUNT(*) FROM realname");
$countdata[0] = mysql_fetch_object($count[0]);
echo $countdata[0];

(p.s. just to clear things up: I want an integer value which is the total number of rows in the table)

    Try it like this

     $count = mysql_query("SELECT * FROM realname");
    $countdata = mysql_num_rows($count);
    echo $countdata;

      Try

      $count[0] = mysql_query("SELECT COUNT(*) FROM realname");
      $countdata[0] = mysql_fetch_row($count[0]);
      echo $countdata[0][0];

      or

      $count[0] = mysql_query("SELECT COUNT(*) as the_count FROM realname");
      $countdata[0] = mysql_fetch_object($count[0]);
      echo $countdata[0]->the_count;

      You could probably drop the "as the_count" if you could figure out what the name of the property would then be called. I've never really seen the point of fetch_object - seeing as all it is is an associative array with different syntax - and you can already fetch an array.....

        Write a Reply...