If the tables have a one to many relationship you can use nested while
loops:

while(1st loop){
    // display header - master table
    while(2nd loop){
        // display features  - detail table

    }
}

HTH

Jayme.


-----Mensagem Original-----
De: olinux <[EMAIL PROTECTED]>
Para: PHP-DB <[EMAIL PROTECTED]>
Enviada em: quinta-feira, 15 de março de 2001 01:05
Assunto: [PHP-DB] 2 while loops - 2 tables


I am trying to display info from 2 tables in a search result format.
My problem is... how do I get the variables to display together?

for example:
A user selects a city to search apartments in.

$sql = "SELECT * FROM $table_name WHERE apt_city = \"$apt_city\"
  ";
$result = mysql_query($sql, $connection);

while ($row = mysql_fetch_array($result)) {
 $aptID = $row['aptID'];
 $apt_address1 = $row['apt_address1'];
 $apt_address2 = $row['apt_address2'];
 $apt_zip = $row['apt_zip'];
}

while ($row = mysql_fetch_array($result)) {
 $apt_ID = $row['apt_ID'];
 $feature1 = $row['feature1'];
 $feature2 = $row['feature2'];
 $feature3 = $row['feature3'];
}


Now I want to display the approriate data from the apartment next to the
features.
so What I am wondering is how can i "group" the appropriate features with
the correct apartment
 so say a result may look like this [HTML table]
______________________________________________
Apartment 1          |   feature1
apt_address1          |   feature2
apt_address2          |   feature3
_________________|_____________________________
Apartment 2          |   feature1
apt_address1          |   feature2
apt_address2          |   feature3
_________________|_____________________________
Apartment 3          |   feature1
apt_address1          |   feature2
apt_address2          |   feature3
_________________|_____________________________

Should the 2nd while loop be placed inside the first?

while ($row = mysql_fetch_array($result)) {
  $aptID = $row['aptID'];
  $apt_address1 = $row['apt_address1'];
   $apt_address2 = $row['apt_address2'];
   $apt_zip = $row['apt_zip'];
    while ($row = mysql_fetch_array($result)) {
      $apt_ID = $row['apt_ID'];
      $feature1 = $row['feature1'];
      $feature2 = $row['feature2'];
      $feature3 = $row['feature3'];
    }
$table_block .= "[ this contains HTML code for table rows to display
data ]";
}

Thanks Much!

olinux




-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to