Welcome Guest, Not a member yet? Register   Sign In
how to fetch data from database automatically on first load
#4

[eluser]alboyd[/eluser]
In your controller you need to make a call to your model to retrieve the selection values - recommend grab an ID and a display value.

In your controller you should save that query result to a variable to pass into the view.

In your view you should iterate through the query results and do as you have already done and create the html for your select dropdown.

EDIT:

Once your query results are in an array available to your view it could look something like this:
Code:
<select name="city" id="city">
     <option value="0">select city</option>
        &lt;?php
        foreach($city_query->result() as $city) { ?&gt;
            <option value="&lt;?php echo $city->id;?&gt;">&lt;?php echo $city->city_name;?&gt;</option>
        &lt;?php } ?&gt;


Messages In This Thread
how to fetch data from database automatically on first load - by El Forum - 08-30-2009, 07:27 AM



Theme © iAndrew 2016 - Forum software by © MyBB