1

in controller i use looping foreach for push array in $dataaray, code push array like bellow :

$dataarray=array();
array_push($dataarray,"{id : ".$idjenis.",JenisPerjal : ".$Jenis.",JmlButuh :".$coba.",JmlTerpasang : ".$coba1.",Sisa : ".$sisa."}");
}
$data=array(
    'data'=> $dataarray,
);
$this->load->view('ExportPdf/exportpdf',$data);

i'm assum you understood for variable $idjenis, $jenis, $coba and $coba1.

result on view like bellow :

id : 5,JenisPerjal : Warning Light,JmlButuh :1,JmlTerpasang : 1,Sisa : 0
id : 7,JenisPerjal : RPPJ,JmlButuh :4,JmlTerpasang : 2,Sisa : 2
id : 8,JenisPerjal : APILL,JmlButuh :1,JmlTerpasang : 1,Sisa : 0
id : 10,JenisPerjal : Water Barier,JmlButuh :1,JmlTerpasang : 1,Sisa : 0

in view i can't get variable of

$data['id'], 
$data['JenisPerjal'], 
$data['JmlButuh'], 
$data['JmlTerpasang '] 
$data['Sisa ']

result in view i want like this

JenisPerjal   | JmlButuh | JmlTerpasang  | Sisa 
===============================================
Warning Light | 1        | 1             | 0
RPPJ          | 4        | 2             | 2
APILL         | 1        | 1             | 0
Water Barrier | 1        | 1             | 0
Adem Natural
  • 105
  • 1
  • 1
  • 10

1 Answers1

1

Modify your array like below

$dataarray[]=array(
   "id"=>$idjenis,
   "JenisPerjal"=>$Jenis,
   "JmlButuh"=>$coba,
   "JmlTerpasang"=>$coba1,
   "Sisa"=>$sisa
);

And in view you can do like below, if you wanna display html table

<?php if (count($data) > 0): ?>
<table>
  <thead>
    <tr>
      <th><?php echo implode('</th><th>', array_keys(current($data))); ?></th>
    </tr>
  </thead>
  <tbody>
<?php foreach ($data as $row): ?>
    <tr>
      <td><?php echo implode('</td><td>', $row); ?></td>
    </tr>
<?php endforeach; ?>
  </tbody>
</table>
<?php endif; ?>
Akshay Hegde
  • 16,536
  • 2
  • 22
  • 36