MySql Query Help: COUNT()
| From: | [-^-!-%- | Date: | Sat, 13 Sep 2003 21:53:36 +0000 |
| Subject: | MySql Query Help: COUNT() | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-162526@lists.php.net to get a copy of this message | ||
Hello everyone!
I'm trying to get the total number of a certain records from a database,
but the result is always '1'. Please advise!
=MySql Table =
=activitiy =
id | employee_id | project_id | date
1 | 45 | 60 | 2003-09-09
2 | 34 | 10 | 2003-09-10
3 | 45 | 45 | 2003-09-10
4 | 23 | 30 | 2003-04-11
Now, I'm trying to get the following info:
- Total Number of employees in the datbase
- Total number of projects
-total number of projects per employee
I currently have
$_sql = "select count(*) as TotalRecords, count(employee_id) as
TotalEmployees, count(project_id) as TotalProjects GROUP BY employee_id,
project_id
$_qry = mysql_query($_sql) or die('...blah...');
$_res = mysql_fetch_object($_qry);
//output
echo $_res->TotalRecords; //prints nothing
echo $_res->TotalEmployees; // returns 1
echo $_res->TotalProjects; //also return 1
//end of code
Any suggestions? Did I miss something?
Please advise.
Thanks in advance.
_john