Welcome Guest, Not a member yet? Register   Sign In
Newbie help--- form_validation ------- set_select
#1

[eluser]Unknown[/eluser]
Hi,

I have a form where the select input is generated dynamically from a database.


So

<select .....>

&lt;?php
for ($i = 1; $i<=num_rows; $i++)
echo "<option ........ $list[$i]['key'] ............ $list[$i]['name'] ";

?&gt;

</select>

How does set_select work for this??? I know how to do it in base php, jquery. Wanted to use the things available in codeigniter rather than base php for the project IM working on.

A redirect to a existing tutorial or topic would solve this for me too. I have tried codeigniter tutorial but I wasnt able to get this part from it.

This probably looked lazy on my part by Im new to codeigniter and Im not used to posting for help. Been a student till recently and havnt needed to post for help. Had help available live.

Thank you,
Ashwin
#2

[eluser]Kyle Johnson[/eluser]
Direct from the user guide:
Code:
<select name="myselect">
<option value="one" &lt;?php echo set_select('myselect', 'one', TRUE); ?&gt; >One</option>
<option value="two" &lt;?php echo set_select('myselect', 'two'); ?&gt; >Two</option>
<option value="three" &lt;?php echo set_select('myselect', 'three'); ?&gt; >Three</option>
</select>

So, that said, each echo of yours would look more like this...
Code:
<select name="whatever">
&lt;?php
for ($i = 1; $i<=num_rows; $i++) {
echo “<option value='{$list[$i][‘key’]}' set_select('whatever')>{$list[$i][‘name’]}</option>“;
}
?&gt;
</select>

Alternately, I've taken a liking to sprintf lately:
Code:
<select name="whatever">
&lt;?php
for ($i = 1; $i<=num_rows; $i++) {
$key = $list[$i][‘key’];
$name = $list[$i][‘name’];
echo sprintf(“<option value='%s' set_select('whatever',%s)>%s</option>“, $key, $key, $name);
}
?&gt;
</select>

My quotes/braces may be off so you'll have to adjust.




Theme © iAndrew 2016 - Forum software by © MyBB