2 while loops - 2 tables

From: Date: Thu, 15 Mar 2001 04:05:30 +0000
Subject: 2 while loops - 2 tables
Groups: php.db 
Request: Send a blank email to php-db+get-7498@lists.php.net to get a copy of this message
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

« previous php.db (#7498) next »