Welcome Guest, Not a member yet? Register   Sign In
controller foreach error
#1

[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>';    
    }
#2

[eluser]stuffradio[/eluser]
It would help if you told us what the error was.
#3

[eluser]Corbee[/eluser]
the debugger said the line containing the foreach in the controller is getting an error
#4

[eluser]Corbee[/eluser]
I think found the error, thanks for the help.




Theme © iAndrew 2016 - Forum software by © MyBB