Re: Displaying Results
| From: | David Robley | Date: | Wed, 17 Apr 2002 02:26:33 +0000 |
| Subject: | Re: Displaying Results | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-93276@lists.php.net to get a copy of this message | ||
In article <63333655c4.655c463333@snowy.gci.net>, solja@gci.net says...
> Suppose I want a script that goes into a table, looks up all records in
> a given field, and groups and displays the results like so:
> match1 (1)
> match2 (5)
> match3 (6)
>
> So basically it looked at the field 'matches' and found a total of 12
> records, 1 record for match1, 5 records for match2, and 6 records for
> match3. It would also be handy for the output to be a link so when you
> clicked on it, it would pass a query on to the database querying for
> just that particular field, like:
> SELECT * FROM table WHERE match="match1"
>
> Can someone point me in the right direction for this? Or show me an
> example script that would accomplish this? Any help would be great.
> Thanks a lot!
For starters, use a query like
SELECT match, COUNT(match) AS howmany FROM table GROUP BY match
which will return results like (from a library app I have):
+-----------+---------+
| surname | howmany |
+-----------+---------+
| AANDAHL | 1 |
| ABEEL | 1 |
| ABERNATHY | 1 |
| ACHEBE | 1 |
| AGATE | 1 |
| ALDISS | 1 |
| ALEXANDER | 1 |
| AMBROSE | 1 |
| AMIS | 2 |
| ANDERSON | 2 |
+-----------+---------+
You can then use the match (surname in the example) value to pass on to a
further query.
--
David Robley
Temporary Kiwi!
Quod subigo farinam