I am trying to create a function that searches the database for stores that are located within the postcode entered by the user in a form by matching the first few letters for example, SW1. So basically:
- User inputs postcode in text box.
- User submits entry.
- Function searches the database for stores that have the same postcode
- Displays results in table.
So far what i have creates a form where the user can enter their postcode, and then an incomplete function that selects the id, name, address etc WHERE the postcodes_covered.
function postcode_lookup()
{
$this->load->helper('form');
$this->layout->view('reports_postcode_lookup_form');
}
function do_postcode_lookup()
{
$this->db->select('id,name, address1,address2,address3,address4,address5,postcode')
->like('postcodes_covered',$this->input->post('postcode'));
}
How can i display the selected data into a table?
This code works. It gets the data from the database and displays it in a table:
function do_postcode_lookup()
{
$data['p'] = $p = $this->input->post('postcode');
$data['postcode'] = array();
$this->db->select('id,name, address1,address2,address3,address4,address5,postcode');
$this->db->like('postcodes_covered', $p);
$bodyshops = $this->db->get('bodyshops')->result();
$this->load->library('Bodyshop', NULL);
foreach($bodyshops as $b)
$data['postcode'][$b->id] = new Bodyshop($b->id, $b);
$this->load->helper('form');
$this->layout->view('reports_postcode_lookup_table', $data);
}