开发者

Help with search query in Codeigniter

开发者 https://www.devze.com 2022-12-23 23:38 出处:网络
Im still fairly new to codeigniter and am wondering if someone can help me with this please? Im just trying to do a very basic search query in Codeigniter, but for some reason, the results are ignori

Im still fairly new to codeigniter and am wondering if someone can help me with this please?

Im just trying to do a very basic search query in Codeigniter, but for some reason, the results are ignoring my "status = published" request...

The code is:

$this->db->like('title', $term);
$this->db->or_like('tags', $term);
$data['results'] = $this->db->get_where('resources', array('status' => 'published'));

And this dosent work either:

$this->db->like('title', $term);
$this->db->or_like('tags', $term);
$this->开发者_如何学Pythondb->where('status', 'published');
$data['results'] = $this->db->get('resources');

Im sure its something basic? Help please?


Try this:

$this->db->from('resources');
$this->db->where('status', 'published');
$this->db->like('title', $term);
$this->db->or_like('tags', $term);
$data['results'] = $this->db->get();

Also a great resource is the last_query:

echo $this->db->last_query(); // Put this after the $this->db->get();


after executing the query do:

var_dump($this->db->last_query());
exit;

this will dump in to the screen the query you are doing, I'm almost sure that this will be one sql issue, and this way it will be easy for you to detect the problem.

Regards,
Pedro

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号