• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
php Export to Excel 2013 Error Call to a Member Function result_array on a non object in c:\xammp\htdocs\mis\application

My File downloads on click of a button but is shows not data from database but shows error in which is state above and below

Quote:Error Call to a Member Function result_array on a non object in c:\xammp\htdocs\mis\application\libraries\export.php oin line 17

Error is on that result_array()

Here is my library export.php
class Export{

function to_excel($array, $filename) {
    header('Content-type: application/vnd.ms-excel');
    header('Content-Disposition: attachment; filename='.$filename.'.xls');

     // Filter all keys, they'll be table headers
    $h = array();
    foreach($array->result_array() as $row){
        foreach($row as $key=>$val){
            if(!in_array($key, $h)){
             $h[] = $key;  
            //echo the entire table headers
            echo '<table><tr>';
            foreach($h as $key) {
                $key = ucwords($key);
                echo '<th>'.$key.'</th>';
            echo '</tr>';

            foreach($array->result_array() as $row){
                 echo '<tr>';
                foreach($row as $val)
            echo '</tr>';
            echo '</table>';

function writeRow($val) {
            echo '<td>'.utf8_decode($val).'</td>';              


Here is my controller
function index()
    $sql = $this->jobs->myqueryfunction();
    $this->export->to_excel($sql, 'nameForFile');

and my model is
function myqueryfunction() {
                $query = "SELECT applicants.*, jobs.position, jobs.jid AS jcid FROM applicants INNER JOIN jobs ON jobs.jid = applicants.jid WHERE date(date_time) >= '0000-00-00' AND date(date_time) <= date(NOW())";
                return $query->result_array();


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

Users browsing this thread:
1 Guest(s)

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2018 MyBB Group.