我有三张桌子:
门
ID | Name | Price | etc.
控制板
ID | Name
门关系
door_id | panel_id
我想为每扇门生成一个 HTML/PHP 表,其中一行显示与其相关的面板:
门单
Name | Price | Panel | etc.
我无法为此编写 MySQL 查询。我应该如何从数据库中请求这些信息?谢谢!
我尝试了什么:
<?php
$catalog_query = mysqli_query($con,"SELECT * FROM door");
$panel_query = mysqli_query($con,"SELECT door.name as door, panel_profile.name as panel FROM door_relationship
INNER JOIN door
ON door_relationship.doorid = door.door_id
INNER JOIN panel_profile
ON door_relationship.panel_id = panel_profile.panel_id
INNER JOIN door");
while($row = mysqli_fetch_array($catalog_query) and $row2 = mysqli_fetch_array($panel_query))
{
echo '<tr>
<td>' . $row['door'] . '</td>
<td>' . $row['description'] . '</td>
<td>' . $row['sqft_price'] . '</td>
<td>' . $row['door_price'] . '</td>
<td>' . $row2['panel'] . '</td>
<td>' . $row['joint'] . '</td>
<td>' . $row['collection'] . '</td>
<td>' . $row['min_sqft'] . '</td>
<td>' . $row['min_width'] . '</td>
<td>' . $row['min_height'] . '</td>
<td>' . $row['max_width'] . '</td>
<td>' . $row['max_height'] . '</td>
</tr>'
;
}
?>