Group mysql rows by column value and split with headings
Hi All
I have searched for the last 3 hours to answer to this but with no luck.
I am not an expert with PHP but can usually put things together which do the job.
The code below looks at a mysql table of UK postcodes and their corresponding cities in the following format:
abbreviation | name | description
AL | St Albans | East Anglia
IP | Ipswich | East Anglia
B | Birmingham | Midlands
CV | Coventry | Midlands
BD | Bradford | North East
Dh | Durham | North East
Currently, the code lists all post codes with it's name in a 4-across grid. However, what I need it to do is group the postcodes by the description to create blocks with the description as the heading, for example:
East Anglia:
[] AL (St Albans) [] IP (Ipswich) ....
Midlands:
[] B (Birmingham) [] CV (Coventry) ......etc
Any help would be greatly appreciated!
PHP Code:
<?php
function system_getUKServiceAreas(){
$sql = "SELECT * FROM UKServiceAreas ORDER BY description";
$result = $dbObj->query($sql);
AL | St Albans | East Anglia
IP | Ipswich | East Anglia
Code:
select col3,group_concat(concat(col1,'delimiter',col2))
group by col 3
should return row like:
East Anglia|AL delimiter St Albans,IP delimiter Ipswich
out of head.
__________________
Found a flower or bug and don't know what it is ? agrozoo.net galery
if you don't spot search button at once, there is search form: agrozoo.net galery search