查看总结果的数量

时间:2017-02-21 10:33:48

标签: php arrays string codeigniter

我的总计数结果看起来像这样现在我想回应它以获得显示但是没有得到

enter image description here

这是我的控制器

  $data['present']= $this->attendance_model->present_report_by_empid($v_employee->user_id,$date);

  $data['presentss']=explode(',',$data['present']);

这是我的观点

 <?php  echo $presentss;?>

这是我的模特

public function present_report_by_empid($user_id = null,$date = null) 
 {


   $temp = explode("-",$date);
   $query='tbl_attendance.date_in';
   $this->db->where('tbl_attendance.attendance_status', 1);
   $this->db->where('tbl_attendance.user_id', $user_id);
   $this->db->where("YEAR(tbl_attendance.date_in)",$temp[0]);
   $this->db->where("MONTH(tbl_attendance.date_in)",$temp[1]);
   $count=$this->db->count_all_results('tbl_attendance');

   return $count;
}

当我像这样更改我的代码时

 $data['present'][]= $this->attendance_model->present_report_by_empid($v_employee->user_id,$date);

并以

视图
  <?php foreach($present as $pe =>$p){?>
                                    <?php echo $p;?>
                                    <?php }?>

我喜欢这个enter image description here

但我希望它像enter image description here

一样

请帮我解决

2 个答案:

答案 0 :(得分:0)

你不需要这个:

<?php echo $presents;?>

您的行数已在

  echo $this->db->last_query();

您可以尝试用来检查您的查询:

$this->db->num_rows();

还切换到检查返回的行以及计数:

style

答案 1 :(得分:0)

试试这样。使用$this->db->num_rows()计算总行数。

<强>模型

public function present_report_by_empid($user_id = null,$date = null) 
 {


   $temp = explode("-",$date);
   $query='tbl_attendance.date_in';
   $this->db->where('tbl_attendance.attendance_status', 1);
   $this->db->where('tbl_attendance.user_id', $user_id);
   $this->db->where("YEAR(tbl_attendance.date_in)",$temp[0]);
   $this->db->where("MONTH(tbl_attendance.date_in)",$temp[1]);
   $result = $this->db->get('tbl_attendance')->result_array();
   $count=count($result); //counts number of rows
   return $count;
}

<强>控制器

$data['present']= $this->attendance_model->present_report_by_empid($v_employee->user_id,$date);

并且

查看

<?php  echo $present;?>
相关问题