Counting problem

Links for php scripts

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 23
Joined: Mon Jul 07, 2003 2:29 pm

Counting problem

Postby icu90ucme » Sun Jul 20, 2003 11:07 pm

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.

User avatar
Posts: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol

Re: Counting problem

Postby WiZARD » Mon Jul 21, 2003 4:28 am

use this:

Code: Select all

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

User avatar
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back

Postby swirlee » Mon Jul 21, 2003 5:43 am

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.

Return to “PHP Scripts”

Who is online

Users browsing this forum: No registered users and 2 guests