Re: [PHP] Group and count at the same time?

2002-08-15 Thread Jeff Lewis

Jason,

Much appreciated, this worked :)

select genre, count('genre') from catalog group by genre
- Original Message -
From: "Jason Wong" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, August 15, 2002 11:26 AM
Subject: Re: [PHP] Group and count at the same time?


> On Thursday 15 August 2002 23:19, Jeff Lewis wrote:
> > I am using PHP to maintain a catalog of music and have been just fine
with
> > it but have run into one thing i want to do and need some advice.
> >
> > The format of the data is like so:
> >
> > upc|genre|distributor|details
>
> Where is this info coming from?
>
> > What I want to do is grab a "summary". So it would end up printing out:
> >
> > rock (43)
> > country (41)
> >
> > and so on. Is this possible to do with one query or will I need to do it
> > with more? So I want to count the number of each genre and provide a
count
> > for each.
>
> If it's from a database then you really should be asking on the php-db
list.
>
> Something like:
>
>   select genre, count('genre') from catalog group by genre
>
> should work.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>


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




Re: [PHP] Group and count at the same time?

2002-08-15 Thread Dan Tappin

I think you want something like this:

SELECT genre, COUNT(*) as count FROM music GROUP BY genre;

Dan

> I am using PHP to maintain a catalog of music and have been just fine with
> it but have run into one thing i want to do and need some advice.
> 
> The format of the data is like so:
> 
> upc|genre|distributor|details
> 
> What I want to do is grab a "summary". So it would end up printing out:
> 
> rock (43)
> country (41)
> 
> and so on. Is this possible to do with one query or will I need to do it
> with more? So I want to count the number of each genre and provide a count
> for each.
> 
> Jeff



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




Re: [PHP] Group and count at the same time?

2002-08-15 Thread Jason Wong

On Thursday 15 August 2002 23:19, Jeff Lewis wrote:
> I am using PHP to maintain a catalog of music and have been just fine with
> it but have run into one thing i want to do and need some advice.
>
> The format of the data is like so:
>
> upc|genre|distributor|details

Where is this info coming from?

> What I want to do is grab a "summary". So it would end up printing out:
>
> rock (43)
> country (41)
>
> and so on. Is this possible to do with one query or will I need to do it
> with more? So I want to count the number of each genre and provide a count
> for each.

If it's from a database then you really should be asking on the php-db list. 

Something like:

  select genre, count('genre') from catalog group by genre

should work.

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




Re: [PHP] Group and count at the same time?

2002-08-15 Thread Adam Williams

You could do it if you had a table with each genre of music.

// get each genre
while ($genre = mysql_fetch_array(mysql_query(select * from genre_table));
{
// sql query to fetch the # of albums of a specific genre
$sql = mysql_query(select count($genre) as count from album_table where
genre =".$genre;

$query = mysql_fetch_row($sql);

// echo the results
echo "You have $query ablums that are $genre";
}

Thats just off top top of my head so it may or may not work.

Adam



On Thu, 15 Aug 2002, Jeff Lewis wrote:

> I am using PHP to maintain a catalog of music and have been just fine with
> it but have run into one thing i want to do and need some advice.
>
> The format of the data is like so:
>
> upc|genre|distributor|details
>
> What I want to do is grab a "summary". So it would end up printing out:
>
> rock (43)
> country (41)
>
> and so on. Is this possible to do with one query or will I need to do it
> with more? So I want to count the number of each genre and provide a count
> for each.
>
> Jeff
>
>
>


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




[PHP] Group and count at the same time?

2002-08-15 Thread Jeff Lewis

I am using PHP to maintain a catalog of music and have been just fine with
it but have run into one thing i want to do and need some advice.

The format of the data is like so:

upc|genre|distributor|details

What I want to do is grab a "summary". So it would end up printing out:

rock (43)
country (41)

and so on. Is this possible to do with one query or will I need to do it
with more? So I want to count the number of each genre and provide a count
for each.

Jeff


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