[英]Php Mysql 3 table Join
and i have some difficulty with php.我对 php 有一些困难。 I have 3 Tables.
我有 3 张桌子。 Table 1 Reference_categories My Table 2 ReferenceTable 3 ref_sel_categories I would like to do inner join between tables, but I couldn't help, can you help?
表 1 Reference_categories 我的表 2 ReferenceTable 3 ref_sel_categories 我想做表之间的内连接,但我帮不上忙,你能帮忙吗?
In the query I wrote below, only ids are coming.在我下面写的查询中,只有 id 来了。 I want category_name to come.
我想要 category_name 来。
Database Tables数据库表
$query = $db->from('reference')
->select('reference.*, GROUP_CONCAT(ref_sel_categories.reference_category_id SEPARATOR \' | \') as categories')
->join('ref_sel_categories', 'FIND_IN_SET(%s.reference_id, %s.reference_id)')
->orderby('reference_order', 'ASC')
->groupBy('reference_id')
->all();
?php foreach ($query as $row): ?>
<tr>
<td width="90"><?= $row['reference_id'] ?></td>
<td><?= $row['reference_title'] ?>
</td>
<td width="200"><?= $row['categories'] ?></td>
</tr>
<?php endforeach; ?>
print_r('$row['categories']')
ref_sel_categories is coming The reference_category_id with
I solved my own question.. maybe it helps others.我解决了我自己的问题..也许它可以帮助别人。
$query = $db->from('reference')
->select('reference.*, GROUP_CONCAT(reference_categories.category_name SEPARATOR \' | \') as categories')
->join('ref_sel_categories', 'reference.reference_id = ref_sel_categories.reference_id ')
->join('reference_categories', 'reference_categories.category_id = ref_sel_categories.reference_category_id')
->orderby('reference_order', 'ASC')
->groupBy('reference_id')
->all();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.