Welcome Guest, Not a member yet? Register   Sign In
Form field data pulled from database
#19

[eluser]mdcode[/eluser]
SUCCESS!!!

Viewing another load of source code, I finally have something that I can work with and it works the way I expected it to. More importantly, I think I can understand why this works and all my previous attempts failed, though I'm going to come up against some stiff opposition later on in the form too. Basically this is the code:

Controller:
Code:
function add()
    {
        $data['siteTitle'] = $this->config->item('siteTitle');
        
        /* grab the customers */
        $customers = $this->projects_model->get_customers();
        
            if ($customers->num_rows() > 0)
            {
                foreach ($customers->result() as $customer)
                {
                $data['values']['customers'][$customer->customerid] = $customer->customerName;
                }
            }
        
        $this->template->write_view('content', 'default/admin/projects_add', $data);
        $this->template->render();
    }

Model:
Code:
function get_customers()
    {
        $query = $this->db->get('customers');
        
        return $query;
    }
    
    function get_customer_name($id = '')
    {
        $query = $this->db->get_where('customers', array('customerid' => $id));
        
        if ($query->num_rows() > 0)
        {
            $row = $query->row();
            
            return $row->customerName;
        }
    }

And View:
Code:
echo form_dropdown('customer', $values['customers']);

And this is the source code that it produces (a drop down list with customer/company id's as the values, but dispaying the corresponding customer name instead:
Code:
<select name="customer">
<option value="1">Company 1</option>
<option value="2">Company 2</option>
</select>

As ever, thanks to you jedd and the Fuzzy 0ne for your continued efforts in helping this noob. Credits to the community! In fact, is there any kind of reputation or thanks giving feature on here, I can't readily see one... I might be blind as well as dense though?


Messages In This Thread
Form field data pulled from database - by El Forum - 03-16-2009, 06:54 PM
Form field data pulled from database - by El Forum - 03-16-2009, 07:09 PM
Form field data pulled from database - by El Forum - 03-16-2009, 07:28 PM
Form field data pulled from database - by El Forum - 03-16-2009, 07:49 PM
Form field data pulled from database - by El Forum - 03-16-2009, 07:55 PM
Form field data pulled from database - by El Forum - 03-16-2009, 07:56 PM
Form field data pulled from database - by El Forum - 03-16-2009, 08:04 PM
Form field data pulled from database - by El Forum - 03-16-2009, 08:12 PM
Form field data pulled from database - by El Forum - 03-16-2009, 08:24 PM
Form field data pulled from database - by El Forum - 03-16-2009, 09:23 PM
Form field data pulled from database - by El Forum - 03-16-2009, 09:58 PM
Form field data pulled from database - by El Forum - 03-16-2009, 11:17 PM
Form field data pulled from database - by El Forum - 03-17-2009, 03:14 AM
Form field data pulled from database - by El Forum - 03-17-2009, 03:30 PM
Form field data pulled from database - by El Forum - 03-18-2009, 06:17 AM
Form field data pulled from database - by El Forum - 03-18-2009, 07:58 AM
Form field data pulled from database - by El Forum - 03-18-2009, 04:17 PM
Form field data pulled from database - by El Forum - 03-18-2009, 05:38 PM
Form field data pulled from database - by El Forum - 03-18-2009, 06:51 PM
Form field data pulled from database - by El Forum - 03-18-2009, 07:10 PM
Form field data pulled from database - by El Forum - 03-18-2009, 07:22 PM
Form field data pulled from database - by El Forum - 03-18-2009, 07:44 PM
Form field data pulled from database - by El Forum - 03-18-2009, 09:00 PM
Form field data pulled from database - by El Forum - 03-18-2009, 09:54 PM



Theme © iAndrew 2016 - Forum software by © MyBB