如何处理 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();

在数据库中它看起来像这样:

https://img1.sycdn.imooc.com/657c053b00011ca106040121.jpg

$get 变量在此表中进行查询。

问题是它不起作用,如果我使用$get_2它可以正常工作,这会是什么?

奇怪,因为这些值与 $get 和 $get_2 完全相同。



偶然的你
浏览 53回答 1
1回答

天涯尽头无女友

也许是因为,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[ 访问它数组索引];
打开App,查看更多内容
随时随地看视频慕课网APP