# request
$ci = &get_instance();
$this->db->where('is_del', 'N');
$this->db->where('depth', '1');
$this->db->from('main_category');
$this->db->order_by('p_category_code asc, depth asc, category_code asc');
$this->db->limit(3, 0);
$res = $this->db->get();
$cat1 = $res->result_array();
?>
$this->db->where('is_del', 'N');
$this->db->where('depth', '2');
$this->db->from('main_category');
$this->db->order_by('p_category_code asc, depth asc, category_code asc');
$res = $this->db->get();
$cat2 = $res->result_array();
$cat_compare = '';
?>
foreach ($cat2
as $key => $data):
?>
if ($data['p_category_code'] != $cat_compare): ?>
$cat_compare = $data['p_category_code'];endforeach; ?>
$this->db->where('is_del', 'N');
$this->db->from('main_category_company');
$this->db->order_by('category_code1,category_code2,display_sort',"asc");
$res = $this->db->get();
$cat2 = $res->result_array();
$cat_compare = '';
foreach ($cat2 as $key => $data):
$code = $data['category_code1']."-".$data['category_code2'];
?>
$cat_compare = $code;endforeach; ?>