[英]PHP Mysql Join issue
I am selecting data from 3 tables using a two left joins. 我正在使用两个左联接从3个表中选择数据。
This all works up until the iteration of one of the values for an association (i think, through process of elimination). 所有这些工作都会一直进行到一个关联值的迭代为止(我认为是通过消除过程)。
I now have reason to believe the select statement is incorrect at the point of the JOINs, but i cannot see how. 我现在有理由相信select语句在JOIN方面是不正确的,但是我看不到如何。
The join that is not functioning as expected: 无法正常运行的联接:
LEFT JOIN
ae_template_pageTypes t ON t.ae_template_pageTypes_id = tp.ae_template_page_group_id
Here i am trying to get the ae_template_pageTypes_type_label
by the ae_template_pageTypes_id
association. 在这里,我想获得的
ae_template_pageTypes_type_label
由ae_template_pageTypes_id
关联。
Table: ae_template_pages 表格: ae_template_pages
Table: ae_template_pageTypes 表格: ae_template_pageTypes
Table: ae_template_groups 表: ae_template_groups
The HTML Output (Both showing HTML instead of using join respectively) HTML输出 (均显示HTML而不是分别使用join)
THE ISSUE I am expecting 2 different values in the format section where here shows both as HTML. 问题我希望在format部分中有2个不同的值,这里都显示为HTML。 I cannot locate why this is happening.
我无法找到原因。
The SELECT 选择
SELECT tg.ae_template_group_name, tp.ae_template_page_id, tp.ae_template_page_group_id, tp.ae_template_page_title, tp.ae_template_page_type, tp.is_group_index, t.ae_template_pageTypes_id, t.ae_template_pageTypes_type_label
FROM
ae_template_pages tp
LEFT JOIN
ae_template_pageTypes t ON t.ae_template_pageTypes_id = tp.ae_template_page_group_id
LEFT JOIN
ae_template_groups tg ON tg.ae_template_group_id = tp.ae_template_page_group_id
WHERE tp.ae_template_page_group_id = '$tempGroup_id'
NOTE: I have tried all types of join to test without finding a solution. 注意:我尝试了所有类型的联接进行测试,但未找到解决方案。
The PHP 的PHP
foreach ($template_pages as $key => $value) {
?>
<li class="dd-item dd3-item" data-id="<? echo $template_pages[$key]['ae_template_page_id']; ?>">
<div class="dd-handle dd3-handle"></div>
<div class="dd3-content ae_template_page" data-template_page_name='<? echo $template_pages[$key]['ae_template_page_title']; ?>' data-template_page_id='<? echo $template_pages[$key]['ae_template_page_id']; ?>'><? echo $template_pages[$key]['ae_template_page_title']; ?>
<span style='float: right;margin-top: -3px;'>
<div style="" class="btn-group">
<span class="btn-info btn-xs dropdown-toggle" data-toggle="dropdown" title="Click to change file type" type="button"><? echo $template_pages[$key]['ae_template_pageTypes_type_label']; ?></span>
<ul role="menu" class="dropdown-menu" data-page_id='<? echo $template_pages[$key]['ae_template_page_id']; ?>'>
<li><a href="#">JS</a></li>
<li><a href="#">HTML</a></li>
<li><a href="#">CSS</a></li>
</ul>
<span class="btn-info btn-xs" title="This file belongs to Template Group: <? echo $template_pages[$key]['ae_template_group_name']; ?>" type="button"><? echo $template_pages[$key]['ae_template_group_name']; ?></span>
<?
if ($template_pages[$key]['is_group_index'] == 1) {
?>
<span class="btn-success btn-xs" title="This is the default file for this group" type="button">Group index</span>
<?
}
?>
</div>
</span>
</div>
</li>
<?
}
SQL workbench output using the above statement with the $tempGroupId set to 1 在$ tempGroupId设置为1的情况下,使用上述语句进行SQL工作台输出
For this and future try and restructure your sql to make it clearer eg: 对于这个和将来,请尝试重组您的sql以使其更加清晰,例如:
select * from (
(select * from table_a) tbla
left join
(select * from table_b) tblb
on tbla.commoncolname=tblb.commoncolname
)
Try this on the database tool first (eg SQL Workbench), then move on to what the php retrieves and so on to the html 首先在数据库工具(例如SQL Workbench)上尝试此操作,然后转到php检索的内容,等等,转到html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.