我有三张桌子
文章
类别
和关系表articles_categories
该表是我使用规范化功能存储我的关系的地方。像这样
我能够选择、插入、更新、删除。这是我之前的问题 Insert , Update , Delete -> Normalization & Code Igniter Saving articles and related categories 按照规范化
我现在想要实现的是我正在尝试通过类别创建文章列表。像这样
Category Name
- article relating to that category
- article relating to that category
- article relating to that category
- article relating to that category
这是我的控制器
function category($id)
{
$data['title'] = "View by category";
$data['articles_categories']=$this->articles_categories_model->get_by_id($id);
$data['articles']=$this->articles_model->get();
$data['category_id']=$id;
$data['categories_list']=$this->categories_model->get();
$this->load->view('articles_pages/category',$data);
}
我的观点
<?php
//$category_id;
foreach($articles as $a)
{
foreach($articles_categories as $ac)
{
if($ac['categories_id']==$category_id && $a['id']==$ac['articles_id'])
{
echo $a['title'];
}
}
}
?>
我无法得到想要的结果。请帮我。谢谢