[eluser]Unknown[/eluser]
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
Code:
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)
$this->writeRow($val);
}
echo '</tr>';
echo '</table>';
}
function writeRow($val) {
echo '<td>'.utf8_decode($val).'</td>';
}
}
Here is my controller
Code:
function index()
{
$this->load->library('export');
$this->load->model('jobs');
$sql = $this->jobs->myqueryfunction();
$this->export->to_excel($sql, 'nameForFile');
}
and my model is
Code:
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();
}