我有兩個表格,房東和房產。我的屬性表有; ID,地址,郵政編碼,租賃和landlordID。我面對的問題是:如果我想搜索所有擁有Mr.Spina作爲房東的房產,我需要在名爲「spina」的房東數據庫中搜索他的ID並將其保存在屬性數據庫中提取屬性的詳細信息。從一個查詢中的兩個mysql表中選擇數據
我認爲這會工作,但它不正確:
> SELECT property.ID, property.address, property.postcode, property.lease, landlords.firstName, landlords.lastName FROM property INNER JOIN landlords ON landlords.firstName LIKE '%spina%' OR landlords.lastName LIKE '%spina%'
我附上的表格結構的圖像。
鬥地主:
只允許一個鏈接
屬性:
http://img5.imageshack.us/img5/7199/propertyn.gif
插入 「脊柱」 進入該領域的結果應該然後是: 只允許一個鏈接
這是我提取的代碼...
> if($field=="landlord"){
>
> $sql="SELECT property.ID, property.address, property.postcode,
> property.lease, landlords.firstName,
> landlords.lastName FROM ".$do." INNER
> JOIN landlords ON landlords.firstName
> LIKE '%".$q."%' OR landlords.lastName
> LIKE '%".$q."%'";
> } else{
> $sql="SELECT * FROM ".$do." WHERE " . $field . " LIKE '%" . $q . "%'";
> } //end special case $result =
> mysql_query($sql);
> echo "$sql";
> echo "<table border='1'>
> <tr>
> <th>ID</th>
> <th>Address</th>
> <th>Post Code</th>
> <th>Lease</th>
> <th>Landlord</th>
> </tr>";
>
> while($row =
> mysql_fetch_array($result))
> {
> echo "<tr>";
> echo "<td>" . $row['ID'] . "</td>";
> echo "<td>" . $row['address'] . "</td>";
> echo "<td>" . $row['postcode'] . "</td>";
> echo "<td>" . $row['lease'] . "</td>";
> echo "<td>" . $row['firstName'] ." ". $row['lastName'] ."</td>";
> echo "</tr>";
> } echo "</table>";
>
> mysql_close();
非常感謝提前!
非常感謝,您的文章用一個組合上面做記號! – nicky 2010-01-22 18:02:23