我似乎遇到了以下代码的问题.当查询没有返回任何内容时,我无法获取插入查询.但是当db中有一行时,else语句会正确运行.有人知道为什么会发生这种情况吗?
$query5 = $this->db->get_where('loggedstatus',array('userid_loggedstatus' => $userid)); if ($query5->num_rows() < 0) { $data1 = array('isLoggedIn_loggedstatus' => 'yes','userid_loggedstatus' => $userid); $this->db->insert('loggedstatus',$data1); } else { $data = array('isLoggedIn_loggedstatus' => 'yes'); $this->db->where('userid_loggedstatus',$userid); $this->db->update('loggedstatus',$data); }
您是否尝试过将此更改为if($query5-> num_rows()< 0){if to if($query5-> num_rows()< = 0){,只是想一想.它会有所不同,因为你告诉它只有在小于零的情况下才执行,但它可能等于零,你会跳到else语句. 并且仅针对CodeIgniter num_rows()引用:
原文链接:https://www.f2er.com/php/135369.html/** * Number of rows in the result set * * @return int */ public function num_rows() { if (is_int($this->num_rows)) { return $this->num_rows; } elseif (count($this->result_array) > 0) { return $this->num_rows = count($this->result_array); } elseif (count($this->result_object) > 0) { return $this->num_rows = count($this->result_object); } return $this->num_rows = count($this->result_array()); }