[eluser]Corbee[/eluser]
I was trying to get the controller to show a listed dropdown
My model seems to be okay, but when trying to display the drop down in the controller I kept getting an error in the foreach
What should I do?
model
Code:
function getcarmodel($brand)
{
$this->db->where('brandID',$brand);
$q = $this->db->get('carmodel');
if ($q->num_rows() > 0)
{
foreach ($q->result_array() as $row)
{
$data[] = $row;
}
$q->free_result();
return $data;
}
}
controller
Code:
function ajaxmodel()
{
$q=$this->MCars->getcarmodel($this->input->post('brand'));
echo '<select name="model" id="model" class="sel">';
foreach($q as $key=>$list)
{
echo '
<option value="' . $list['modelID'] . '">' . $list['modelName'] . '</option>
';
}
echo '</select>';
}