Code Igniter - form_dropdown selecting correct value from the database

前端 未结 5 1346
傲寒
傲寒 2021-01-05 18:52

Im having a few problems with the form_dropdown function in CodeIgniter .... My application is in 2 parts, a user goes in, enters a form and submits it .... once its submitt

5条回答
  •  迷失自我
    2021-01-05 19:47

    I had the same problem but i have overcome on this problem using code igniter syntex. Here is the solution. Fisrt step Before the loop initialize two arrays

    $options = array();
    $select = array();
    

    Then in the loop write this instruction

    foreach($result->result_array() as $row)
    {
        /////////Your Condition ////////////
        if($row['id'] == $myarray['mycolumn'])
        {            
            $options [$row['id']] = $row['salaryrange'];
            $select = $row['id'] ; 
        }else{
            $options [$row['id']] = $row['salaryrange'];
        }
    }
    

    Now

    echo form_dropdown('dropdown_name' , $options , $select);
    

    It is working ok

提交回复
热议问题