好吧,这显然不是完整的代码,但这是错误所在的代码。
$this->db->select('post_likes');
$this->db->from('user_dash_posts');
$this->db->where('post_idn', $idn);
$this->db->where('isactive', '0');
if($this->db->count_all_results() > 0)
{
$dataDB = $this->db->get();
对于这里显示的最后一行的
get()
语句,我得到的是“No table used”。我对整个CI数据库类/助手还是比较陌生的,因为我以前更喜欢手写完整的查询器。但我试着让自己学习ORM层,更好地熟悉它们。不过,这对我的问题来说是个哑巴。我试图找出我做错了什么,什么是解决办法,如果有可能的话,解释一下我做错了什么,这样我就可以理解,而不是再次。 最佳答案
根据documentation:
通常,当一个活动记录调用完成时,所有存储的信息都会重置为下一个调用。
如果要重用查询,请使用可以在同一页底部找到的缓存方法。完成后不要忘记刷新缓存:
$this->db->start_cache();
$this->db->select('post_likes');
$this->db->from('user_dash_posts');
$this->db->where('post_idn', $idn);
$this->db->where('isactive', '0');
$this->db->stop_cache();
if($this->db->count_all_results() > 0) {
$dataDB = $this->db->get();
}
$this->db->flush_cache();
编辑:
使用单个查询而不是两个查询的另一个选项:
$this->db->select('post_likes');
$this->db->from('user_dash_posts');
$this->db->where('post_idn', $idn);
$this->db->where('isactive', '0');
$query = $this->db->get();
if($query->num_rows() > 0) {
$dataDB = $query->result();
}