Codeigniter中的搜索查询帮助
我对codeigniter还是一个新手,我想知道是否有人能帮我解决这个问题 我只是想在Codeigniter中做一个非常基本的搜索查询,但是由于某些原因,结果忽略了我的“status=published”请求 代码是:Codeigniter中的搜索查询帮助,codeigniter,Codeigniter,我对codeigniter还是一个新手,我想知道是否有人能帮我解决这个问题 我只是想在Codeigniter中做一个非常基本的搜索查询,但是由于某些原因,结果忽略了我的“status=published”请求 代码是: $this->db->like('title', $term); $this->db->or_like('tags', $term); $data['results'] = $this->db->get_where('resources', a
$this->db->like('title', $term);
$this->db->or_like('tags', $term);
$data['results'] = $this->db->get_where('resources', array('status' => 'published'));
这两种方法都有效:
$this->db->like('title', $term);
$this->db->or_like('tags', $term);
$this->db->where('status', 'published');
$data['results'] = $this->db->get('resources');
我肯定这是最基本的?请帮忙?试试这个:
$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();
最后一个查询也是一个很好的资源:
echo $this->db->last_query(); // Put this after the $this->db->get();
执行查询后,执行以下操作:
var_dump($this->db->last_query());
exit;
这将在屏幕上显示您正在执行的查询,我几乎可以肯定这将是一个sql问题,这样您就可以很容易地检测到问题
问候,Pedro您可以使用查询功能$this->db->query('SELECT*FROM table WHERE status=published');将所有SQL查询放在那里进行测试。