Welcome Guest, Not a member yet? Register   Sign In
Form Dropdown From Database Display Error
#1

[eluser]jvk22[/eluser]
I'm using the form helper to populate a drop down, however when I put the database generated array in form_dropdown() it does not display correctly.

This is what the drop down looks like and the values are id and name
0
1
USA
1
2
U.K.

The actual id should be the value and the actual name should display

Current Source:
<select name="country">
<optgroup label="0">
<option value="id">2</option>

<option value="name">test</option>
</optgroup>
<optgroup label="1">
<option value="id">1</option>
<option value="name">United States</option>
</optgroup>
</select>

What I'm trying to achieve
<select name="country>
<option name="1>USA</option>
<option name="2">U.K.</option>
</select>
#2

[eluser]toopay[/eluser]
Use foreach statement. And when you post code, please use code tags
Code:
// Remove any spaces
[ code]<--YourCodeHere--&gt;[ /code]
#3

[eluser]jvk22[/eluser]
How exactly would I write the foreach though?
#4

[eluser]danmontgomery[/eluser]
Code:
$dropdown = array();
foreach($db_result->result() as $row) {
    $dropdown[$row->id] = $row->name;
}

echo form_dropdown('country', $dropdown);

http://ellislab.com/codeigniter/user-gui...sults.html




Theme © iAndrew 2016 - Forum software by © MyBB