2016-12-15 21 views
0

我從來沒有在之前的Codeigniter中將它導出到v2下的PDF MySQL。但是當我切換到v3.1.0時,導出到PDF的問題在foreach有什麼問題?在導出pdf時使用html2pdf的foreach錯誤數組在codeigniter中

ERORR

甲PHP錯誤遇到

嚴重性:注意

消息:未定義偏移:1

文件名:HTML2PDF/html2pdf.class.php

控制器

public function print_data(){ 
    ob_start(); 
    $class= $this->uri->segment(3); 
    $data = array(
        'get_data' => $this->My_model->detail_id_data($class) 
    ); 
    $this->load->view('print_detail_data', $data); 
    $html = ob_get_contents(); 
    ob_end_clean(); 

    require_once('./assets/html2pdf/html2pdf.class.php'); 
    $pdf = new HTML2PDF('P', 'A4', 'en', true, 'UTF-8', 3); 
    $pdf->WriteHTML($html); 
    $pdf->Output('id_detail.pdf'); 
} 

Models 

    function detail_id_data($class) { 
     $query = $this->db->select('*') 
          ->from('tb_student') 
          ->where('class', $id_data) 
          ->get(); 

     if ($query->num_rows() > 0) { 
      foreach ($query->result() as $data) { 
       $hasil[] = $data; 
      } 
      return $hasil; 
     } 
    } 

查看

<table style="width: 100%; border: solid 1px black;"> 
    <thead> 
     <tr> 
     <th>ID</th> 
     <th>Name </th> 
     <th>Class</th> 
     <th>Study</th> 
     </tr> 
    </thead>  
    <tbody> 
    <?php 
     $no=1; 
     foreach ($get_data as $row){  
    ?> 
     <tr> 
     <td><?php $no; ?></td> 
     <td><?php echo $row->name; ?></td> 
     <td><?php echo $row->class; ?></td> 
     <td><?php echo $row->study; ?>f</td>   
     </tr> 
    <?php $no++; } ?> 
    </tbody> 
</table> 
+0

的價值是什麼的模型'$ id_data'價值? –

+0

其值varchar ex = class-ix。所以我想讓那裏的學生在ix, –

+0

'where'('class-xi')'這樣? –

回答

0

在模型中使用row()result()代替..hope它將作品。

if ($query->num_rows() > 0) { 
      foreach ($query->row()) as $data) { 
       $hasil[] = $data; 
      } 
      return $hasil; 
     } 

更改您的視圖像這樣的....

<table style="width: 100%; border: solid 1px black;"> 
    <thead> 
     <tr> 
     <th>ID</th> 
     <th>Name </th> 
     <th>Class</th> 
     <th>Study</th> 
     </tr> 
    </thead>  
    <tbody> 
    <?php 
     $no=1; 
     foreach ($get_data as $row){  
    ?> 
     <tr> 
     <td><?php $no; ?></td> 
     <td><?php echo $row['name']; ?></td> 
     <td><?php echo $row['class']; ?></td> 
     <td><?php echo $row['study']; ?>f</td>   
     </tr> 
    <?php $no++; } ?> 
    </tbody> 
</table> 

在控制器,

更換它..

$data = array(
        'get_data' => $this->My_model->detail_id_data($class) 
    ); 

通過

$data['get_data'] = $this->My_model->detail_id_data($class); 

您是否獲得$class。嘗試以下

echo $class; 
+0

仍然錯誤不能解決 –

+0

你正在發送'$ get_data'作爲array.so嘗試這個改變,希望它正在工作。 –

+0

同樣仍然是錯誤 –

相關問題