How to add sub category on my codeigniter php application ?
Posted
by
sagarmatha
on Stack Overflow
See other posts from Stack Overflow
or by sagarmatha
Published on 2011-02-09T21:38:45Z
Indexed on
2011/02/10
7:25 UTC
Read the original article
Hit count: 129
codeigniter
Hello friends
I have a view
echo "<label for='parent'>Category</label><br/> ";
echo form_dropdown('category_id', $categories). "<p>";
controller
function create(){
if($this->input->post('name')){
$this->MProducts->addProduct();
$this->session->set_flashdata('message', 'Products Created');
redirect('admin/products/index', 'refresh');
}else{
$data['title'] = "Create Product";
$data['main'] = 'admin_product_create';
$data['categories']= $this->MCats->getTopCategories();
$this->load->vars($data);
$this->load->view('dashboard');
}
}
and the model is
function getTopcategories(){
$data = array();
$data[0] = 'root';
$this->db->where('parentid',0);
$Q = $this->db->get('categories');
if($Q->num_rows() > 0){
foreach($Q->result_array() as $row){
$data[$row['id']] = $row['name'];
}
}
$Q->free_result();
return $data;
}
Basically, what i want is we get sub categories when we click categories and 'selected' subcategory id goes to database when we create products, So that we can list products by sub categories. Please help me how do we do that ?
© Stack Overflow or respective owner