Welcome Guest, Not a member yet? Register   Sign In
select box, mySQL, form_validation and form_helper
#1

[eluser]Neeraj Kumar[/eluser]
Hi all!



I have a huge list of years, from 1900 - 2009. Now following is my problem

I need to store data into MySQl DB, this is what I do in view, when a user registers at site for the first time:

Code:
<select name="year" id="year">
    <option value="-1" &lt;?php echo set_select('year', '-1') ?&gt;>Select</option>
    &lt;?php
        for($ctr = 1900; $ctr <=date('Y'); $ctr+=1)
        echo "<option value='$ctr'" . set_select('year', $ctr) . ">$ctr</option>"
    ?&gt;
</select>

I can run form_validation etc. perfectly. The problem arises when I want a user to edit this field again.

For that I present him another view viz. 'edit_view'. Now what and how should I create this drop down dynamically and present him all the fields with the one stored in the database as selected.

I tried to use form_dropdown(), but where am supposed to specify the set_select() so that when form is submitted and processed, user can see last selected value just like he saw in registration form
#2

[eluser]Neeraj Kumar[/eluser]
come on, somebody?

I need a solution to this problem... please
#3

[eluser]spheroid[/eluser]
Assuming in your controller you pass the selected year to $data['year'], and add all the values of the years into an array, such as $year_array, you could do this:

Code:
$year_array = array();
for ($ctr = 1900; $ctr <= date('Y'); $ctr++) {
    array_push($year_array, $i);
}

echo form_dropdown('year', $year_array, ($this->input->post('year') ? $this->input->post('year') : $year));




Theme © iAndrew 2016 - Forum software by © MyBB