Re: 2 while loops - 2 tables
| From: | David | Date: | Fri, 16 Mar 2001 18:56:15 +0000 |
| Subject: | Re: 2 while loops - 2 tables | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-7547@lists.php.net to get a copy of this message | ||
It is a little hard to advise on this without knowing the table schema, but
it is generally best to make the database do as much of the work as possible
rather than use logic in your script because databases are specifically
optimized for what they do. If I were trying to do what you are talking
about, I would try to use a join in my query. For help with join syntax,
see
http://www.mysql.com/documentation/mysql/bychapter/manual_Reference.html#JOI
N.
In your case, if the aptID field is shared, and there is a one-to-one
relationship between the tables (there is a row in each table for each
apartment), the query might look something like this:
$sql = "SELECT * FROM $table1, $table2 WHERE table1.aptID=table2.atpID AND
table1.apt_city = \"$apt_city\" ";
Each row of the result set will include the data from both tables.