Welcome Guest, Not a member yet? Register   Sign In
How to select value in dropdown from query?
#1

[eluser]jplanet[/eluser]
I am sure many of you have successfully accomplished this:

I have a simple form where customers can edit their address. I can query the database for the customer address and populate all of the fields with:

Code:
$this->load->model('customer_model');

//return row with address data
$billing = $this->customer_model->getBilling($this->session->userdata('customer_id'));

////set validation rules etc.

$this->validation->set_fields($fields);
        
        $this->validation->bill_first_name = $billing->first_name;
        $this->validation->bill_last_name = $billing->last_name;
        $this->validation->bill_company_name = $billing->company_name;
        $this->validation->bill_address = $billing->address;
        $this->validation->bill_city = $billing->city;

This all works beautifully. But, when I get to the state dropdown, no luck:

Quote:$this->validation->bill_state = $billing->state;

There is no state selected even through $billing->state returns a value that has a match in the form.

My state dropdown looks like this (abbreviated):

Code:
<select name="bill_state" id="bill_state">

<option value="" selected>Select a State</option>
<option value="AL" &lt;?= $this->validation->set_select('bill_state', 'AL'); ?&gt;>Alabama</option>
<option value="AK"  &lt;?= $this->validation->set_select('bill_state', 'AK'); ?&gt;>Alaska</option>
<option value="AZ" &lt;?= $this->validation->set_select('bill_state', 'AZ'); ?&gt;>Arizona</option>
<option value="AR" &lt;?= $this->validation->set_select('bill_state', 'AR'); ?&gt;>Arkansas</option>
<option value="CA" &lt;?= $this->validation->set_select('bill_state', 'CA'); ?&gt;>California</option>
<option value="CO" &lt;?= $this->validation->set_select('bill_state', 'CO'); ?&gt;>Colorado</option>
<option value="CT" &lt;?= $this->validation->set_select('bill_state', 'CT'); ?&gt;>Connecticut</option>
<option value="DE" &lt;?= $this->validation->set_select('bill_state', 'DE'); ?&gt;>Delaware</option>

etc...

Any suggestions would be appreciated!


Messages In This Thread
How to select value in dropdown from query? - by El Forum - 11-30-2007, 11:58 AM
How to select value in dropdown from query? - by El Forum - 12-03-2007, 07:57 PM
How to select value in dropdown from query? - by El Forum - 12-03-2007, 08:19 PM
How to select value in dropdown from query? - by El Forum - 12-03-2007, 11:31 PM



Theme © iAndrew 2016 - Forum software by © MyBB