count(*) query

Hi,

am doing something wrong, for sure... I just fail to see it atm where
the failure is. Call me stupid :p

Someone have a look please

<?php

require 'inc/mysql.inc';
require 'inc/functions.inc';

$result = mysql_query ("SELECT count(*) FROM User", $connection);

echo ($result);

?>



The answer I get is Resource id#4 instead of 6 which is the number of
rows in the User table.

Thanks,
twomt.
twomt [ Do, 14 September 2006 21:07 ] [ ID #1466583 ]

Re: count(*) query

twomt wrote:
> Hi,
>
> am doing something wrong, for sure... I just fail to see it atm where
> the failure is. Call me stupid :p
>
> Someone have a look please
>
> <?php
>
> require 'inc/mysql.inc';
> require 'inc/functions.inc';
>
> $result = mysql_query ("SELECT count(*) FROM User", $connection);
if($result) {
$row=mysql_fetch_array($result);
echo $row[0];
} else {
echo "Didn't find any users in the User table.\n";
}
>
> ?>
>
>
>
> The answer I get is Resource id#4 instead of 6 which is the number of
> rows in the User table.

Yes, you haven't fetched the data, you need to use mysql_fetch_array() or any
other of the fetch functions, the resource is used to tell what you want to
fetch (can do more than one query at the same time).


//Aho
Shion [ Do, 14 September 2006 21:17 ] [ ID #1466584 ]

Re: count(*) query

J.O. Aho wrote:
> twomt wrote:
>> Hi,
>>
>> am doing something wrong, for sure... I just fail to see it atm where
>> the failure is. Call me stupid :p
>>
>> Someone have a look please
>>
>> <?php
>>
>> require 'inc/mysql.inc';
>> require 'inc/functions.inc';
>>
>> $result = mysql_query ("SELECT count(*) FROM User", $connection);
> if($result) {
> $row=mysql_fetch_array($result);
> echo $row[0];
> } else {
> echo "Didn't find any users in the User table.\n";
> }
>>
>> ?>
>>
>>
>>
>> The answer I get is Resource id#4 instead of 6 which is the number of
>> rows in the User table.
>
> Yes, you haven't fetched the data, you need to use mysql_fetch_array()
> or any other of the fetch functions, the resource is used to tell what
> you want to fetch (can do more than one query at the same time).
>
>
> //Aho

erm.... I think I better take a break :p
where's my beer :D

Thanks, knew it was a silly one.
twomt [ Do, 14 September 2006 21:27 ] [ ID #1466585 ]
PHP » alt.php.sql » count(*) query

Vorheriges Thema: Can anyone help a newbie figure out MySQL?
Nächstes Thema: MySQL bug? or user error?