$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;
}
}
这对我有用:)