繁体   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