使用CodeIgniter并排显示类别 [英] Show categories side-by-side using CodeIgniter
本文介绍了使用CodeIgniter并排显示类别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用Codeigniter并列列出类别和子类别。就像这里一样: http://prntscr.com/mtj2ov
I want to list categories and subcategories side-by-side using Codeigniter. just like here: http://prntscr.com/mtj2ov
for example:
Flowers
Flowers -> Rose
Flowers -> Tulips
Flowers -> Lilies
表
Table
id - subid - category_name - category_description - status
1 0 Flowers - 1
2 1 Rose - 1
3 1 Tulips - 1
此模型内容
This model content
public function getCategoryTree($id=0, $sub_mark=''){
$rows = $this->db->select('*')->where('subid', $id)->order_by('id','asc')->get('ci_category')->result();
$category = '';
if (count($rows) > 0) {
foreach ($rows as $row) {
$category .= '<option value="'.$row->id.'">'.$sub_mark.$row->category_name.'</option>';
$category .= $this->getCategoryTree($row->id, $sub_mark.'--');
}
}else{
return false;
}
return $category;
}
此控件内容
This Control content
$data['all_categroy'] = $this->category_model->get_all_category();
与示例一样,我需要如何更改模型和控制文件
as with the example, how I need to make a change in the model and control file
推荐答案
尝试一下,
$result = $this->db->select('*')->order_by('id','asc')->get('ci_category')->result();
$parentName = '';
$select = "<select>";
foreach ($result as $r) {
if ($r->subid == 0) {
$select.= "<option id='" . $r->id . "' >" . $r->category_name . "</option>";
$parentName = $r->c_name . ' --> ';
} else {
$select.= "<option id='" . $r->id . "' >" . $parentName . $r->category_name . "</option>";
}
}
$select.= "</select>";
echo $select;
die;
这篇关于使用CodeIgniter并排显示类别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文