0

I am getting an Undefined table data error in CodeIgniter and can't figure out why. When I first try and echo the example table from the CI website, everything works fine:

function ajaxAvgSalePriceTable(){
$this->load->library('table');
$query = array(
         array('Name', 'Color', 'Size'),
         array('Fred', 'Blue', 'Small'),
         array('Mary', 'Red', 'Large'),
         array('John', 'Green', 'Medium')   
         );
echo $this->table->generate($query);
}  

However, when I try to use my own query, I get the Undefined table data error. Here is the code that is causing the error:

function ajaxAvgSalePriceTable(){
    $this->load->library('table');
    $muni = $this->input->POST('muni');
    $query = "SELECT SaleYear AS Y, NewSaleType AS T, count(*) AS C, tblsales.Municipality AS M, format((sum(SalePrice) / sum(Quantity1)),0) AS R FROM tblsales WHERE   tblsales.SaleYear > 2007 AND tblsales.Quantity1 > 2000 AND (tblsales.NewSaleType = 'Industrial') AND tblsales.Municipality = '".$muni."' GROUP BY T,M,Y ORDER BY T,M,Y";
    echo $this->table->generate($query);
}  

Can anyone see what I might be doing wrong? I have tested this query separately and it works fine elsewhere, just not working here.

1 Answer 1

1

change this like following, You forgot to get data from query.

function ajaxAvgSalePriceTable(){
    $this->load->library('table');
    $muni = $this->input->POST('muni');
    $query = "SELECT SaleYear AS Y, NewSaleType AS T, count(*) AS C, tblsales.Municipality AS M, format((sum(SalePrice) / sum(Quantity1)),0) AS R FROM tblsales WHERE   tblsales.SaleYear > 2007 AND tblsales.Quantity1 > 2000 AND (tblsales.NewSaleType = 'Industrial') AND tblsales.Municipality = '".$muni."' GROUP BY T,M,Y ORDER BY T,M,Y";

$res = $this->db->query($query);
$data = $res->result_array();

    echo $this->table->generate($data);
}  
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your help Mansoorkhan. You spotted the problem exactly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.