Coba ini..
Kueri semua kota dengan negara bagian, pesan berdasarkan negara bagian terlebih dahulu lalu berdasarkan kota:
SELECT id, alphaname, state
FROM regional
ORDER BY state ASC, alphaname ASC
Atur kumpulan data Anda menjadi larik 2 dimensi:
$states = array();
while($thearray = mysql_fetch_array($list))
{
$states[$thearray[state]][$thearray[id]] = $thearray[alphaname];
}
Sekarang isi $states
your Anda akan terlihat seperti:
Array
(
[AK] => Array (
[id_1] = Anchorage
[id_2] = Juneau
)
[CA] => Array (
[id_3] = Los Angeles
[id_4] = San Diego
[id_5] = San Francisco
)
)
Buat presentasi HTML Anda:
CATATAN:Tambahkan jangkar untuk mencerminkan pertanyaan yang diajukan.
foreach($states as $state_name => $cities)
{
echo '<h3>'.$state_name.'</h3>';
echo '<ul>';
foreach($cities as $id => $city_name)
{
echo '<li><a href="info.html?id='.$id.'">'.$city_name.'</a></li>';
}
echo '</ul>';
}