Welcome Guest, Not a member yet? Register   Sign In
Excel Exporting Problem in Codeignitor
#1

[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;'>&lt;?=$row->orderdate?&gt;</td>
                                <td align= center style='border:#94D5FC solid 1px;padding:5px;'>&lt;?=$row->fname?&gt; &lt;?=$row->lname?&gt;</td>
                                <td align= center style='border:#94D5FC solid 1px;padding:5px;'>&lt;?=$row->name?&gt;</td>
                                <td align= center style='border:#94D5FC solid 1px;padding:5px;'>&lt;?=$row->pid?&gt;</td>
                                <td align= center style='border:#94D5FC solid 1px;padding:5px;'>&lt;?=$row->quantity?&gt;</td>
                                <td align= center style='border:#94D5FC solid 1px;padding:5px;'>&lt;?=$row->pprice?&gt;</td>
                                <td align= center style='border:#94D5FC solid 1px;padding:5px;'>&lt;?=$row->srate?&gt;</td>
                                <td align= center style='border:#94D5FC solid 1px;padding:5px;'>&lt;?=$row->trate?&gt;</td>
                                <td align= center style='border:#94D5FC solid 1px;padding:5px;'>$&lt;?=$row->subtotal?&gt;</td>
                             </tr>
                             &lt;?php
                            }
                            }
                           else {
                                 echo "No Results Found !";
                                }
                            ?&gt;
                        </table>
                        <div>Generate Excel Report<a href="&lt;?=base_url()?&gt;admin.php?report/generateexcel/&lt;?php echo $result; ?&gt;"><img src="&lt;?=base_url()?&gt;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.




Theme © iAndrew 2016 - Forum software by © MyBB