I'm trying to send from a controller to a view an array of all contacts who are in my database table "Contacts" and then display them on a drop down menu.I followed the CodeIgniter documentation about this topic http://codeigniter.com/user_guide/general/views.html but it isn't really what I would like to do. Here is what I tried to do :
function getAll_contact(){
$exist= $this->contacts_model->get_all('contacts');
if($exist)
{
$all_contact = $this->contacts_model->read('contacts');
//echo json_encode($all_contact); prints all the contacts in the table
$this->load->view('myView', $contact);
}
}
In my view :
<select class="span4">
<?php if(isset($all_contact) && ! empty($all_contact)){
foreach($all_contact as $contact){
echo "<option value='".$contact->id_contact."'>".$contact->company."</option>";
}
}
</select>
This does not show anything on the drop down menu. Could anyone help me please ?