表:类别
表:category_child_title
表:category_child
预期产出就像这样
我试过了sofar
$sql = "SELECT * FROM category WHERE is_deleted = 0";
$query = $this->db->query($sql);
$categories = $query->result_array();
foreach($categories as $key => $category)
{
$cat_id = $category['id'];
// $sql = "SELECT child.name as childName, group_concat(title.name) as titleName
// FROM category_child AS child
// LEFT JOIN category_child_title AS title on child.fk_category_child_title = title.id
// WHERE child.fk_category = $cat_id AND child.is_deleted = 0
// ";
//
$sql = "SELECT name, fk_category_child_title FROM category_child WHERE fk_category = $cat_id AND is_deleted = 0";
$query = $this->db->query($sql);
$categoryChild = $query->result_array();
$categories[$key][] = array( 'childs' => $categoryChild);
}
输出
任何帮助请