Welcome Guest, Not a member yet? Register   Sign In
Foreach as List
#1

[eluser]RedIgniter[/eluser]
OK, I want a dropdown box where values = id values from the table and the option shows the name of a certain subject lets say the subject name is Math, I want it to be like <option value='1'>PHP</option> I wrote some code where it creates array with all results that match with that user, basically here is my code

Code:
$subject_delete = array(
foreach($query->result() as $row)
{
    $row->id => $row->subject;    
}
);

where $row->id is the id and $row->subject is the subject name; just like 'php' => 'PHP' in usual dropdown in CI

i am more than sure I am doing this wrong, what will be the right way to do it?
#2

[eluser]Dennis Rasmussen[/eluser]
Documentation: http://ellislab.com/codeigniter/user-gui...elper.html

Your code:
Code:
$options = array();

foreach($query->result() as $row)
{
    $options[$row->id] = $row->subject;
}

echo form_dropdown('field_name', $options);




Theme © iAndrew 2016 - Forum software by © MyBB