Re: [PHP] PHP and MySQL sorting using COUNT

2002-11-13 Thread @ Edwin
Hello,

[EMAIL PROTECTED] wrote:

 
 I'm sorting records using COUNT with the following mysql command
 
 $result = mysql_query (SELECT company_name, agent_name, count(*) FROM
 $cur_listings GROUP BY company_name, agent_name);
 
 Running this in MySQL does exactly what I need it to do but how do I echo
 the COUNT portion of the array? I know the company_name would be
 $row['company_name'] and agent_name is $row['agent_name']; 

You can find something about aliases here:

  http://www.mysql.com/doc/en/SELECT.html

- E


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] PHP and MySQL sorting using COUNT

2002-11-13 Thread Steve Edberg
Actually, using your original query and referring to

	$row['count(*)']

would work too. However, when using calculated fields I always use a 
column alias as Rich recommends - it makes things a lot clearer.

-steve


At 1:54 PM + 11/13/02, Rich Gray [EMAIL PROTECTED] wrote:
try '... ,count(*) as count ...' then you should be able to reference it as
$row['count']
HTH
Rich
-Original Message-
From: [EMAIL PROTECTED] [mailto:ed;home.homes2see.com]
Sent: 13 November 2002 13:44
To: [EMAIL PROTECTED]
Subject: [PHP] PHP and MySQL sorting using COUNT



I'm sorting records using COUNT with the following mysql command

$result = mysql_query (SELECT company_name, agent_name, count(*) FROM
$cur_listings GROUP BY company_name, agent_name);

Running this in MySQL does exactly what I need it to do but how do I echo
the COUNT portion of the array? I know the company_name would be
$row['company_name'] and agent_name is $row['agent_name'];

Thanks,

Ed Curtis



--
++
| Steve Edberg  [EMAIL PROTECTED] |
| University of California, Davis  (530)754-9127 |
| Programming/Database/SysAdmin   http://pgfsun.ucdavis.edu/ |
++
| SETI@Home: 1001 Work units on 23 oct 2002  |
| 3.152 years CPU time, 3.142 years SETI user... and STILL no aliens...  |
++

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php