Counting problem

A

Anonymous

Guest
when i input the mysql code on the command line, i get an accurate result but when i try to use the same code in php i get a result of "Resource id#9" -- Does anybody know what this means

$query = mysql_query("SELECT COUNT(*) FROM pepinfo");

echo 'Number of people in database: '.$query.' ';

if confused on what i'm saying the variable $query prints out "Resource id # 9" instead of the number of people in my database.
 
use this:
Code:
$query = mysql_query("SELECT * FROM pepinfo");
 
No, icu90ucme, it's not your query that's the problem. If you refer to the documentation, you'll see that a call to mysql_query() returns a resource identifier, which is exactly what you get when you try to echo its value. It doesn't return a string or a number -- you can't just echo it. Remember, if you're having trouble with a particular function, the best first step to solving it is reading the documentation.

Now, in order to make use of the resource, you have to use a function like mysql_fetch_array(), which will fetch a row from the result set and return it as an array. The examples on that page should be more than enough to get you started.
 
Back
Top