I am attempting to achieve the following result in CodeIgniter

```
SELECT location, COUNT(location), AVG(review) FROM progrodb.tickets WHERE datesubmitted BETWEEN '2018-9-1' AND '2018-9-30' AND location = 'location'

```

The output needs to be;

```
Location|Total Tickets|Avg Review<br>
location|3            |4.5

```

This table should include the result for each location. The SQL statement as is provide the results for a single location now I need this to be done for a total of 22 locations.

I have tried the following attempt but after a var\_dump() results return null

```
public function generatereport(){
        // Set Page Title
        $this->data['page_title'] = 'Generate Report';

        $rules = $this->support_m->rules_report;
        $this->form_validation->set_rules($rules);

        $startdate = $this->input->post('startdate');
        $enddate = $this->input->post('enddate');
        define('locations', array('Shoppers Fair Blue Diamond', 'Shoppers Fair Burke Road', 'Shoppers Fair Brunswick', 'Shoppers Fair Duhaney Park', 'Shoppers Fair Greater Portmore', 'Shoppers Fair View', 'Shoppers Fair Junction', 'Shoppers Fair Liguanea', 'Shoppers Fair Manchester'));

         if ($this->form_validation->run() == TRUE){
            $results = $this->db->select('location, count(location) as location_count, AVG(review) as review_avg')
            ->where('datesubmitted BETWEEN "'.$startdate.'" AND "'.$enddate.'"')
            ->group_by('location') 
            ->get('tickets')->result();
            var_dump($results);

         }

        // Load view    
        $this->data['subview'] = 'admin/tickets/report';
        $this->load->view( 'admin/body', $this->data );

    }

```

And got the following dump now I'm trying to pass the results to the view but I receive the errors Undefined variable: reports and Trying to get property of non-object.

[![enter image description here](https://i.stack.imgur.com/I9JGG.png)](https://i.stack.imgur.com/I9JGG.png)

[![enter image description here](https://i.stack.imgur.com/9VJXT.png)](https://i.stack.imgur.com/9VJXT.png)