获取当前user_id的产品

时间:2015-06-01 06:55:56

标签: php mysql codeigniter

我有从ci_products表中获取产品的功能 代码如下

function get_product_selections($product_ids = array())
{
    $this->db->select('*');
    $this->db->from('ci_products');
    $this->db->where_in('product_id', $product_ids);

    $products = $this->db->get();
    return $products;
}

现在我想从user_id current user_id的哪个位置抓取 我尝试了一些但没有工作的东西 我尝试了什么?

function get_product_selections($product_ids = array())
{
    $this->db->select('*');
    $this->db->from('ci_products');
    $this->db->where_in('product_id', $product_ids);
      $this->db->where('user_id',$this->session->userdata('user_id'));
    $products = $this->db->get();
    return $products;
}

2 个答案:

答案 0 :(得分:1)

$data = $this->db->get_where('product_ids',$product_ids);
$this->db->where_in('product_ids',$data);
$this->db->where('user_id',$this->session->userdata('user_id'));
$query =  $this->db->get();
return $query->result_array();

答案 1 :(得分:0)

试试这个:

在您的第一个代码中:

function get_product_selections($product_ids)
{
    $this->db->select('*');
    $this->db->from('ci_products');
    $this->db->where('product_id', $product_ids);

    $products = $this->db->get();
    return $products->result_array();
}

在参数中放入array()是什么意思?你想要检索产品的数组()吗?

function get_product_selections()
{
    $this->db->select('*');
    $this->db->from('ci_products');
    $this->db->where('user_id',$this->session->userdata('user_id')); // the user who is currently login
    $products = $this->db->get();

    return $products->result_array(); // return the results
}