I am trying to display a set of offices ordered under a header that reflects the state in which the offices are located, like so:
State
Office
Office
...
State
Office
...
I have beat my head against this one for a while. There is a single table 'offices' in the MySQL db which has each office's State listed under 'office_state'. Here's what I've come up with - but nothing is returned.
// Here I return a list of the distinct States:
$stateQuery = 'SELECT DISTINCT office_state AS state FROM offices';
$stateResult = mysql_query($stateQuery);
// Here I return each office's information:
$officeQuery = 'SELECT office_information, office_state FROM offices';
$officeResult = mysql_query($officeQuery);
// And here's where I'm stuck:
while ($rows = mysql_fetch_assoc($stateResult)) {
// This returns the distinct States:
echo $rows['state'];
// Here is my effort at listing each office within the State:
$rows1 = mysql_fetch_assoc($officeResult);
if ($rows['state'] == $rows1['office_state']) {
echo $rows1['office_information'];
}
}
Any help would be much appreciated.