A quick question, which I think has a very simple solution for those who have something above the most basic knowledge of PHP / MySQL, like me.
I have a list of cities in different states stored in a database with the city, state and some other variables. Right now they are being pulled like a list sorted by city name:
- Anchorage, AK
- Baltimore, MD
- Chicago, Illinois, etc.
First, I want to be able to group by state, and then list all cities that have this state value. So it will look like this:
AK
CA
- Los Angeles
- San diego
- San Francisco
- etc.
I know that I need to do some kind of foreach and search the Internet, but have not found an example that I can get to work.
:
$list = mysql_query("SELECT id, alphaname, state FROM regional ORDER BY alphaname",$db);
while ($thearray = mysql_fetch_array($list)) {
echo "<li><a href='info.html?id=$thearray[id]'>$thearray[alphaname], $thearray[state]</a></li>";
}
, , , - , ...
!
- . rockacola, i-g .