Welcome Guest, Not a member yet? Register   Sign In
How to automatically choose the correct value in a select box when loading data from database
#1

[eluser]tochie[/eluser]
Hi Brethren,

I want to automatically choose the correct value in a select box when loading data from database. E.g. When displaying a form for editing (data is loaded from db), the select box for 'year' should have the year previously entered into the database.

I couldn't find it in the form helper. Please anyone know how i can do this with CI?

Thanks
#2

[eluser]verynewtothis[/eluser]
This has been discussed here
#3

[eluser]n0xie[/eluser]
You can find it here: http://ellislab.com/codeigniter/user-gui...rreference

Code:
<select name="myselect">
&lt;?php ($somevalue == $dbvalue) ? $boolean = TRUE : $boolean = FALSE; ?&gt;

<option value="one" &lt;?php echo set_select('myselect', 'one', $boolean); ?&gt; >One</option>
</select>

You have to write an if statement to match the value against your database value. If it matches, set boolen to true else set it to false
#4

[eluser]tochie[/eluser]
Thanks ppl. Your suggestions were helpful. One CI! One Luv!




Theme © iAndrew 2016 - Forum software by © MyBB