Welcome, Guest. Please login or register.
Did you miss your activation email?
05/23/12, 12:26
Home Help Search Login Register
News: Parsley Flex framework review featuring quiz application, in our Flex frameworks series
Flex SDK 4.5 mobile roadmap: begin with your mobile development
Swiz Flex framework review featuring quiz application
New homepage we release our new Homepage, take a look ...

+  Flash-db
|-+  Server side Scripting and Database Support
| |-+  PHP, Perl, ASP, JSP, CFM (Moderators: Flash-db, Musicman, vesa kortelainen, Ronald Wernecke, Jorge Solis, nothingGrinder)
| | |-+  loops in loops
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] Print
Author Topic: loops in loops  (Read 1344 times)
GordonC
Server what's that
*
Posts: 13



View Profile WWW Email
« on: 06/10/02, 20:01 »

Hello -

I have a table that has various world cities (field city_name) - every city also has a country field (country)

I currently have a drop down list that displays ALL of the cities - what I want is for them to be broken down by country, with the relevant cities listed under every country.

What I have is:

$result = mysql_query("SELECT * FROM cities ORDER BY city_name",$db);

$myrow = mysql_fetch_array($result);

<select name="selected_city" >
                     <option selected></option>
                     <?php do { ?>
                     <option value="<?php echo $myrow["city_name"];?>">
                     <? echo $myrow["city_name"];?>
                     <? } while($myrow = mysql_fetch_array($result)); ?>
                     </option>
                   </select>

which works fine, but give me:

Berlin
Bordeaux
Hamburg
London
Manchester
Paris

I'm assuming I would have to create a loop within a loop do to what I want, though, which is:

France
  Bordeaux
  Paris
Germany
 Berlin
 Hamburg
England
 London
 Manchester


Any ideas?

Gordon
Logged
Pages: [1] Print 
« previous next »
Jump to:  


Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
anything