我无法修复代码中的错误。它导致一个数据。我需要的是使用这一行循环并从数据库中获取所有数据。
控制器
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++;
}
}
答案 0 :(得分: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++;
}
}