Forum Moderators: open
$query="select state from states";
$result=mysql_query($query);
while($row=mysql_fetch_assoc($result)) {
extract($row); //turns state into a variable $state$query2="select city from cities where state='$state'";
$result2=mysql_query($query2);
while($row=mysql_fetch_assoc($result2) {
extract($row2);
echo "$city, $state<BR>";
} //end of city while loop
} //end of state while loop
There might be a way to use a subquery which would be faster and require far less code but would be more restrictive. Depends on the output you need.
[webmasterworld.com...]
[webmasterworld.com...]
or you may be able to use a CASE structure of sorts, something along these lines
[webmasterworld.com...]