I have a SQL table with two fields: City and State. I would like to build a simple list of all states and all respective cities, but until now could not. I would like something like this:
<ul>
<li>New York
<ul>
<li>Albany</li>
<li>Buffalo</li>
<li>New York City</li>
</ul>
</li>
<li>Illinois
<ul>
<li>Chicago</li>
<li>Rockford</li>
</ul>
</li>
</ul>
I did the below select, but it list only the states. Can't find a way to show respective cities:
<?php
$result = mysqli_query($con,"SELECT DISTINCT states,cities FROM table ORDER BY states");
while($row = mysqli_fetch_array($result))
{
// show here
}
?>