如何使用codeigniter显示mysql数据透视表数据

时间:2019-02-01 08:32:16

标签: php mysql codeigniter-3

我,我尝试将我的表格列数据显示在一行中... mysql查询是可行的,但我无法获取数据显示

     function get_daily_attendances_row($fldCompanyStringID){

            $fldCompanyID = getCoompanyByStringID($fldCompanyStringID)->fldCompanyID;
$sql = "SELECT *

    , SUM(CASE WHEN `fldAttendanceAction` = '0' THEN `fldAttendanceTime` END) AS `OUT`
    , SUM(CASE WHEN `fldAttendanceAction` = '1' THEN `fldAttendanceTime` END) AS `IN`
    , SUM(CASE WHEN `fldAttendanceAction` = '2' THEN `fldAttendanceTime` END) AS `LUNCH IN`
    , SUM(CASE WHEN `fldAttendanceAction` = '3' THEN `fldAttendanceTime` END) AS `LUNCH OUT`
  FROM `tblAttendance`
  WHERE fldUserID = ". loggedInUserID() ." AND  fldCompanyID = $fldCompanyID
  GROUP BY `fldAttendanceDate`";
          $query = $this->db->query($sql);      

          $result = $query->result_array(); 

我想在我的视图表中显示该值

这是我的控制器

$data['get_daily_attendances_row'] = $this->M_attendance->get_daily_attendances_row($fldCompanyStringID);
}

1 个答案:

答案 0 :(得分:0)

我建议您将查询转换为mysql上的存储过程,并从codeigniter执行SP。