[PHP] Help getting count to show up.

2002-09-10 Thread Chuck Payne

Hi,

Last night I asked for help doing counts. One of the answers I got was
really great but I can't make it work. The answer I more or less show me a
great way to create a stats page,

ex. SELECT feild1, field2, COUNT(*) FROM tables GROUP BY category, format.

But my problem is I can't get count to show. I can get two of the fields.

Below is the PHP program that I am wanting to run. How can I get count to
show? Thanks.

Chuck Payne
Magi Design and Support




?

$db = mysql_connect('localhost','user','passwd');
mysql_select_db('media',$db);

$result =mysql_query(SELECT category, format, COUNT(*) FROM library GROUP
BY category, format,$db);

if ($myrow = mysql_fetch_array($result)) {

// display list if there are no records to display

do  {



printf(%s %s %sbr, $myrow[category], $myrow[format], $myrow[count]);

} while ($myrow = mysql_fetch_array($result));

} else {

// no record to display

echo 'Sorry no records were found!';

}


?



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




RE: [PHP] Help getting count to show up.

2002-09-10 Thread David Buerer

SELECT feild1, field2, COUNT([insert field name here]) FROM tables GROUP BY
category,format

--or--

SELECT feild1, field2, COUNT([insert field name here]) as mycount FROM
tables GROUP BY category,format

-Original Message-
From: Chuck Payne [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, September 10, 2002 3:25 PM
To: [EMAIL PROTECTED]
Subject: [PHP] Help getting count to show up.


Hi,

Last night I asked for help doing counts. One of the answers I got was
really great but I can't make it work. The answer I more or less show me a
great way to create a stats page,

ex. SELECT feild1, field2, COUNT(*) FROM tables GROUP BY category, format.

But my problem is I can't get count to show. I can get two of the fields.

Below is the PHP program that I am wanting to run. How can I get count to
show? Thanks.

Chuck Payne
Magi Design and Support




?

$db = mysql_connect('localhost','user','passwd');
mysql_select_db('media',$db);

$result =mysql_query(SELECT category, format, COUNT(*) FROM library GROUP
BY category, format,$db);

if ($myrow = mysql_fetch_array($result)) {

// display list if there are no records to display

do  {



printf(%s %s %sbr, $myrow[category], $myrow[format],
$myrow[count]);

} while ($myrow = mysql_fetch_array($result));

} else {

// no record to display

echo 'Sorry no records were found!';

}


?



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




RE: [PHP] Help getting count to show up.

2002-09-10 Thread David Freeman


  ex. SELECT feild1, field2, COUNT(*) FROM tables GROUP BY 
  category, format.

Try this instead:

  SELECT field1, field2, COUNT(*) AS field3 FROM TABLS GROUP BY
category,format

Now you'll find your count is available as 'field3'.

CYA, Dave




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