drnpwmq4536 2013-07-02 18:38
浏览 21

Codeigniter Undefined Index在线商店

Codeigniter Undefined Index Online Shop:

For some reason i am getting back "Undefined index: grouping in the controller.

I have added both the controller and the model below.

I have just added the getProduct() code as well

/*Here is my model*/
  function getProductsByGroup($limit,$group,$skip){
     $data = array();
     if ($limit == 0){
        $limit=3;
     }
     $this->db->select('id,name,shortdesc,thumbnail');
     $this->db->where('grouping', $group);
     $this->db->where('status', 'active');
     $this->db->where('id !=', ($skip));
     $this->db->order_by('name','asc');
     $this->db->limit($limit);
     $Q = $this->db->get('products');
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
         $data[] = $row;
       }
    }
    $Q->free_result();    
    return $data; 
 }  

/*getProduct()*/
function getProduct($id){

        $data = array();
        $option = array('id' => $id);
        /*pass the id and other options to the category*/
        $Q = $this->db->get_where("categories",$option,1);
        if ($Q ->num_rows() > 0){
            $data = $Q->row_array();
        }
        $Q->free_result();
        return $data;
    }


/*This is my controller*/
    public function product($id)
    {
        $product = $this->MProducts->getProduct($id); 

        if (!count($product))
        {
        redirect('welcome/index','refresh'); 
        }

/* This is where the error is coming from*/
        $data['grouplist'] =  $this->MProducts->getProductsByGroup(3,$product['grouping'],$id);
        $data['product'] = $product;
        $data['title'] = "Claudia’s Kids | ". $product['name']; 
        $data['main'] = 'product';
        $data['navlist'] = $this->MCats->getCategoriesNav(); 
        $this->load->vars($data); 
        $this->load->view('template');
    }
  • 写回答

3条回答 默认 最新

  • duan_88598 2013-07-02 18:56
    关注

    add the grouping column to the select in the getProductsByGroup function

    $this->db->select('id,name,shortdesc,thumbnail, grouping');
    

    The error is stating that $product['grouping'] is not set. If you look at your select statement you can see that you are not selecting the grouping column.

    评论

报告相同问题?

悬赏问题

  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答