0

我有三张桌子:

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>'
        ;
}
?>  
4

3 回答 3

1

查询必须是:

select d.name doorName, p.name panelName, otherFields from Door d, Panel p, Door-Relationship r where p.id = r.panel_id and d.id = r.door_id group by d.id order by d.id asc
于 2013-06-28T20:42:37.213 回答
1

这可能会有所帮助(未经测试):

SELECT
  door.id AS door_id,
  door.name AS door_name,
  door.price AS door_price,
  door.etc AS door_etc,
  panel.id AS panel_id,
  panel.name AS panel_name
FROM door, panel
INNER JOIN door_relationship
  ON door_relationship.door_id = door_id
  AND door_relationship.panel_id = panel_id
于 2013-06-28T20:17:44.890 回答
0
SELECT d.Name, d.Price, p.Name, etc

FROM Door d, Panel p, Door-Relationship DR

WHERE d.id = dr.door_id and p.id = dr.panel_id;
于 2013-06-28T20:17:03.893 回答