vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| I've set up 2 queries that enable me to nest a list of cities within a list of counties. The queries work, but I thought this might be a good learning opportunity and was wondering if there is a way to do this within the sql query with some sort of group by and join query. $query = "select County,count(*) as list from residential group by County order by county asc"; $result = db_query("$query"); while ($counties = db_fetch_object($result)) { $output .= "<div class='county'>$counties->County ($counties- >list)</div>"; $q2 = "select City,count(*) as list from residential where County='$counties->County' group by City order by list desc"; $r2 = db_query("$q2"); while ($cities = db_fetch_object($r2)) { $output .= "<div class='county'>$cities->City ($cities->list)</ div>"; } } In mysql 4.x, s there a way to do this within the sql code rather than in the code for the programming language? |