Codeigniter未定义索引在线商店 [英] Codeigniter Undefined Index Online Shop

查看:131
本文介绍了Codeigniter未定义索引在线商店的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Codeigniter未定义索引在线商店:

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.

我也刚刚添加了getProduct()代码

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');
    }

推荐答案

已解决..但是我必须承认我喜欢这个论坛:

Solved..But i must confess i love the forum :

我在这里使用类别表而不是产品表.

I was getting the using the category table here instead of the product table.

/*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); i just changed this line to 
        $Q = $this->db->get_where("product",$option,1);
        if ($Q ->num_rows() > 0){
            $data = $Q->row_array();
        }
        $Q->free_result();
        return $data;
    }

这篇关于Codeigniter未定义索引在线商店的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆