Welcome Guest, Not a member yet? Register   Sign In
Select options with foreach from database
#1

[eluser]someone Smile[/eluser]
Hello!

I'm working on my first CodeIgniter project and I'm new to PHP (I know basic functions).

How can I do select options with foreach? I'm using view, model and controller, but I actually don't know how to do this.

Code in view:
Code:
<select name="selectlist">
&lt;?php foreach ($select as $listitem): ?&gt;
<option value="">&lt;?=$listitem?&gt;</option>
&lt;?php endforeach; ?&gt;
</select>

Code in controller:
Code:
$this->load->model('AddOrderInsert');
$select = $this->AddOrderInsert->select_result();

Code in model:
Code:
function select_result() {
    $query = $this->db->query("SELECT title FROM list");
    $row = $query->row_array();    
    return array($row);
}

Thanks for help in advance! :-)




Theme © iAndrew 2016 - Forum software by © MyBB