簡體   English   中英

從mysql中的兩個表中檢索數據

[英]retrieve data from two tables in mysql

我的數據庫中有兩個表。 1 =屬性(包含屬性的圖像)2 =構建器(包含構建器的徽標)

我已經從屬性表中檢索了數據並顯示在表中,如下所示:。

  <?php



        while($list = mysqli_fetch_array($result) ){



            echo"<tr>";
            echo"<td>".$list['id']."</td>";
            echo"<td>".$list['owner']."</td>";
            echo"<td>".$list['purpose']."</td>";
            echo"<td>".$list['property_type']."</td>";
            echo"<td>".$list['city']."</td>";
            echo"<td>".$list['location']."</td>";
            echo"<td>".$list['description']."</td>";
            echo"<td>".$list['price']."</td>";
            echo"<td>".$list['land_area']."</td>";
            echo"<td>".$list['bedrooms']."</td>";
            echo"<td>".$list['bathrooms']."</td>";
            echo"<td>".$list['property_expire']."</td>";
            echo"<td>"."<img height='50' width='50' src='".$list['image_url']."'/>"."</td>";
            echo "<td><a href=\"edit_property.php?id=$list[id]\">Edit</a> | <a href=\"delete_property.php?id=$list[id]\" onClick=\"return confirm('Are you sure you want to delete?')\">Delete</a></td>";

            echo"</tr>";


            }


         ?>

我想要的是:顯示我已經完成的屬性表的所有內容,但是我也想從生成器表中獲取生成器徽標...我該怎么辦?

您可以在查詢中使用類似的內容。

Select P.propertyId, L.logoName from properties as P
Left Join logos as L ON P.logo_id = L.id 

使用表propertiesbuilders進行簡單的聯接查詢:

SELECT pr.propertyId, bu.logoName 
FROM properties as pr
LEFT JOIN builders as bu ON pr.logo_id = bu.id 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM