如何处理查询中收到的数据 Codeigniter
How to handle data received in a query Codeigniter
我有以下内容:
$get = array(trim($this->db->get_where('base', array('key' => 'courses'))->row('value'), '"[]'));
//$get_2 = array('1', '2', '3');
$this->db->order_by("id", "desc");
$this->db->limit('8');
$this->db->where('status', 'active');
$this->db->where_in('id', $get);
return $this->db->get('course')->result_array();
在数据库中它看起来像这样:
$get
变量使查询在此table。
问题是用不了,如果我用$get_2
就可以正常使用,请问是什么问题?
奇怪,因为值与 $get
和 $get_2
.
完全相同
可能是因为,IF $get 的输出是 '1','2','3',那样放入数组中失败了。试试 explode();:
$get = str_replace("'", "", trim($this->db->get_where('base', array('key' => 'courses'))->row('value'), '"[]'));
$get_data = explode(',',$get);
//$get_2 = array('1', '2', '3');
$this->db->order_by("id", "desc");
$this->db->limit('8');
$this->db->where('status', 'active');
$this->db->where_in('id', $get_data);
return $this->db->get('course')->result_array();
现在,它变成了$get_data中的一个数组,您可以通过$get_data[array_index访问它]];
我有以下内容:
$get = array(trim($this->db->get_where('base', array('key' => 'courses'))->row('value'), '"[]'));
//$get_2 = array('1', '2', '3');
$this->db->order_by("id", "desc");
$this->db->limit('8');
$this->db->where('status', 'active');
$this->db->where_in('id', $get);
return $this->db->get('course')->result_array();
在数据库中它看起来像这样:
$get
变量使查询在此table。
问题是用不了,如果我用$get_2
就可以正常使用,请问是什么问题?
奇怪,因为值与 $get
和 $get_2
.
可能是因为,IF $get 的输出是 '1','2','3',那样放入数组中失败了。试试 explode();:
$get = str_replace("'", "", trim($this->db->get_where('base', array('key' => 'courses'))->row('value'), '"[]'));
$get_data = explode(',',$get);
//$get_2 = array('1', '2', '3');
$this->db->order_by("id", "desc");
$this->db->limit('8');
$this->db->where('status', 'active');
$this->db->where_in('id', $get_data);
return $this->db->get('course')->result_array();
现在,它变成了$get_data中的一个数组,您可以通过$get_data[array_index访问它]];