2016-09-07 36 views
2

我無法修復我的代碼中出現問題。它導致一個數據。我需要的是循環並使用這些行從數據庫中獲取所有數據。PHPExcel如何使用codeigniter動態設置單元值

控制器

function firstDebit(){ 
$series=$this->uri->segment(3); 

$this->db->select ('accountcode.accountName'); 
$this->db->from ('accountcode'); 
$this->db->join ('generalaccount ', 'generalaccount.AccountCode = accountcode.id'); 
$this->db->where ('generalaccount.Series', $series); 
$this->db->where ('generalaccount.Account', 'debit'); 
$this->db->where ('generalaccount.Count', 1); 
$query = $this->db->get(); 
$query->row_array(); 

$rowNumber=10; 

foreach($query->row_array() as $rows){ 
    $this->excel->setCellValue('b'.$rowNumber, $rows); 
    $rowNumber++; 

} 

}

回答

2

我想你需要的是result_array所以你的代碼將

function firstDebit(){ 
    $series=$this->uri->segment(3); 

    $this->db->select ('accountcode.accountName'); 
    $this->db->from ('accountcode'); 
    $this->db->join ('generalaccount ', 'generalaccount.AccountCode = accountcode.id'); 
    $this->db->where ('generalaccount.Series', $series); 
    $this->db->where ('generalaccount.Account', 'debit'); 
    $this->db->where ('generalaccount.Count', 1); 
    $query = $this->db->get(); 

    $rowNumber=10; 

    foreach($query->result_array() as $rows){ 
     $this->excel->setCellValue('b'.$rowNumber, $rows['accountName']); 
     $rowNumber++; 

    } 
} 
+0

我用它開本,但它會產生一個錯誤。 甲PHP錯誤遇到 嚴重性:注意 消息:未定義偏移量:0 文件名:細胞/ DefaultValueBinder.php 行號:82 回溯: 文件:C:\ XAMPP \ htdocs中\ ACC \ application \ third_party \ PHPExcel \ Cell \ DefaultValueBinder.php 行:82 函數:_error_handler – Nexus

+0

作爲使用結果數組的結果,您必須使用$ rows ['accountName']作爲單元格值。 – follio

+0

它的作品!非常感謝Follio :) – Nexus