CodeIgniter Forums

Full Version: checkbox
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,
I use the CodeIgniter 3.0.1 (is too old for upgrade and I have lots of problems after it)

So, this is the edit page of the product, the array is working insert on my db like as: a:1:{i:0;s:2:"1 ";} but if I try to edit again the checkbox is not are selected.

my Controllers:
PHP Code:
public function edit($id) {
 
       if ($this->input->post('name')) {
 
           $data['name'] = $this->input->post('name');
 
           $data['model'] = $this->input->post('model');
 
           $data['category_id'] = serialize($this->input->post('category_id'));
 
           $data['brand_id'] = $this->input->post('brand_id');
 
           $data['price'] = $this->input->post('price');
 
           $data['tag_line'] = $this->input->post('tag_line');
 
           $data['features'] = $this->input->post('features');
 
 
           $this->product->update($data$id);

 
           redirect('/admin/products''refresh');
 
       }

 
       $product $this->product->get($id);
 
       $brands $this->brand->get_all();
 
       $categories $this->category->get_all();

 
       $data['brands'] = $brands;
        
$data['categories'] = $categories;
 
       $data['product'] = $product;
 
       $data['page'] = $this->config->item('ci_my_admin_template_dir_admin') . "products_edit";
 
       $this->load->view($this->_container$data);
 
   

View page:
PHP Code:
<?php
$i 
0;
foreach(
$categories as $key => $category)
{
?>
  <label>
          <input type="checkbox" name="category_id[]" value="<?= $category['id'?> <?= ($product->category_id == $category['id']) ? 'checked="checked"' ''?>"> <?= $category['name'?></input>
           <br />
   </label>
 <?php
$i
++;
}
?>

get_all function:
PHP Code:
public function get_all($fields ''$where = array(), $table ''$limit ''$order_by ''$group_by '') {
        
$data = array();
        if (
$fields != '') {
            
$this->db->select($fields);
        }

        if (
count($where)) {
            
$this->db->where($where);
        }

        if (
$table != '') {
            
$this->table_name $table;
        }

        if (
$limit != '') {
            
$this->db->limit($limit);
        }

        if (
$order_by != '') {
            
$this->db->order_by($order_by);
        }

        if (
$group_by != '') {
            
$this->db->group_by($group_by);
        }

        
$Q $this->db->get($this->table_name);

        if (
$Q->num_rows() > 0) {
            foreach (
$Q->result_array() as $row) {
                
$data[] = $row;
            }
        }
        
$Q->free_result();

        return 
$data;
    } 

What I can do it?