2017-02-21 39 views
-2

我總數的結果是這樣的,現在我想呼應它,以獲得顯示,但它沒有得到查看總成績的計

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

p租賃幫助我解決

+1

你的問題沒有任何意義。請具體解釋你想達到的目標。 – Callombert

+1

你能顯示更多代碼嗎?因爲您正在使用'echo $ presentss'但從未定義過儘可能多的 –

+0

分享您的模型文件代碼以及 – Vinay

回答

0

你不需要這樣的:

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

你的行號已在

<?php echo $presents;?> 

你可以嘗試用它來檢查你的查詢:

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

還切換到檢查返回的行以及計數:

$this->db->num_rows(); 
+0

yaa但是當我在視圖頁中回顯那些全部爲'0' –

+0

那麼這就是返回的行數。 – Callombert

+1

你可以試試$ this-> db-> last_query();檢查您的查詢是否正確,並在phpmyadmin中運行它。 – Callombert

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;?> 
+0

當我使用你的代碼我得到這樣的'消息:調用未定義的方法CI_DB_mysqli_driver :: num_rows()' –

+0

現在試試我編輯它。 –

+0

@ user_777你解決了嗎? –