[eluser]aruntvla[/eluser]
I need to export a search result to excel sheet,when i export it ,it showing error as
'A PHP Error was encountered
Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: plugins/to_excel_pi.php
Line Number: 13
A PHP Error was encountered
Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: plugins/to_excel_pi.php
Line Number: 17 '
my
view page.
from here passing the array to controller
Code:
<?php
if(count($result > 0))
{
foreach($result as $row)
{
?>
<tr>
<td align= center style='border:#94D5FC solid 1px;padding:5px;'><?=$row->orderdate?></td>
<td align= center style='border:#94D5FC solid 1px;padding:5px;'><?=$row->fname?> <?=$row->lname?></td>
<td align= center style='border:#94D5FC solid 1px;padding:5px;'><?=$row->name?></td>
<td align= center style='border:#94D5FC solid 1px;padding:5px;'><?=$row->pid?></td>
<td align= center style='border:#94D5FC solid 1px;padding:5px;'><?=$row->quantity?></td>
<td align= center style='border:#94D5FC solid 1px;padding:5px;'><?=$row->pprice?></td>
<td align= center style='border:#94D5FC solid 1px;padding:5px;'><?=$row->srate?></td>
<td align= center style='border:#94D5FC solid 1px;padding:5px;'><?=$row->trate?></td>
<td align= center style='border:#94D5FC solid 1px;padding:5px;'>$<?=$row->subtotal?></td>
</tr>
<?php
}
}
else {
echo "No Results Found !";
}
?>
</table>
<div>Generate Excel Report<a href="<?=base_url()?>admin.php?report/generateexcel/<?php echo $result; ?>"><img src="<?=base_url()?>system/application/admin/images/excel_icon.gif" border="0" width="20px" height="20px"/></a></div>
controller page function is
Code:
function generateexcel($array)
{
$this->load->plugin('to_excel');
// $query = $this->db->get('order_productinfo');
$query = $array;
// print_r($array);
to_exceltoarray($query, 'myfile');
}
and the
plugin contains function to_exceltoarray(),function code is
Code:
function to_exceltoarray($array, $filename='out') {
header('Content-type: application/vnd.ms-excel');
header('Content-Disposition: attachment; filename='.$filename.'.xls');
echo '<table><tr>';
foreach($array[0] as $key=>$val)
echo '<th>'.$key.'</th>';
echo '</tr>';
foreach($array as $key=>$val)
_writeRow($val);
echo '</table>';
}
function _writeRow($row, $isHeader=false) {
echo '<tr>';
foreach($row as $r) {
if($isHeader)
echo '<th>'.$r.'</th>';
else
echo '<td>'.$r.'</td>';
}
echo '</tr>';
}
how i pass this array to plugin function.plz give me suggestion.