Welcome Guest, Not a member yet? Register   Sign In
Data population in form_dropdown

My model code is


$query = $this->db->get();
if ($query->num_rows() > 0)
foreach ($query->result() as $row)
line 249 -------------- $options[ $row['makeId'] ] = $row['makename'];
return $options;

My Controller code is

$data['lkmake'] = $this->ads_model->Getmake(); //make

My view code is

But i am still getting an error "Fatal error: Cannot use object of type stdClass as array in C:\xampp\htdocs\dev.com\system\application\models\ads_model.php on line 249"

i am newbie in CI world please guide where i am doing wrong.

try $row->makeId = $row->makename your getting object not array from result

Thanks Umer

but still getting error Sad

what sort of error you are getting post here well i have one helper to create database driven dropdown here is code you have to get you values as id and name

$this->db->select(‘makeId as id’,‘makename as name’);

if(! function_exists('form_db_dropdown')){
    function form_db_dropdown($data=''){
        $rows = $data['rows'];
        (array_key_exists('options',$data))?$options = $data['options']:$options = '';
        if(count($rows) && !empty ($rows)) {
            foreach($rows as $row){
                $options[$row->id] = $row->name;              
        (array_key_exists('selected',$data))?$selected = $data['selected']:$selected = '';
        (array_key_exists('extra',$data))?$extra = $data['extra']:$extra = '';
        (array_key_exists('class',$data))?$extra = 'class= "'.$data['class'].'"':$extra = '';
        return form_dropdown($data['name'],$options,$selected,$extra);

$rows = $query->result() ;


try it, will work

Theme © iAndrew 2016 - Forum software by © MyBB