[英]num_rows() returns 1 even when there are rows
$this->db->select_sum('score_0')
->select_sum('score_1')
->select_sum('score_2')
..........
->select_sum('score_97')
->select_sum('score_98')
->select_sum('score_99');
$this->db->where('score_game_id',$game_id);
$this->db->order_by('score_id','asc');
$query = $this->db->get($this->tbl_lotteryApp_scores_twodigit);
if ($query->num_rows() > 0){
}
可能是什么原因?
即使返回的每个值都是零,也总是会返回一行,因为您必须按要求返回这些零值(从命令行运行sql并查看)。 您需要获取查询结果并检查其值以查看其实际值。
我认为这是针对这种情况的最佳解决方案:
function sum_score($game_id){
if($this->check_for_scores($game_id)==true)
{
$this->db->select_sum('score_0')
->select_sum('score_1')
->select_sum('score_2')
...........
->select_sum('score_98')
->select_sum('score_99');
$this->db->where('score_game_id',$game_id);
$this->db->order_by('score_id','asc');
$query = $this->db->get($this->tbl_lotteryApp_scores_twodigit);
return $query->result();
}
}
function check_for_scores($game_id)
{
$this->db->where('score_game_id',$game_id);
$this->db->order_by('score_id','asc');
$query = $this->db->get($this->tbl_lotteryApp_scores_twodigit);
if ($query->num_rows() > 0){
return true;
}else{
return false;
}
}
这对我有用:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.