Welcome Guest, Not a member yet? Register   Sign In
Dynamically fill an array from Mysql using Form Helper for dropdown list.
#2

[eluser]Mike Ryan[/eluser]
Hi Datguru,

Are you only seeing one supplier in the dropdown menu? If so, it is because of this line:

Code:
$data['options'] = array( $row->supplier_id => $row->supplier_name);

$data['options'] is being overwritten each time the loop executes, so only the last pair will show in the dropdown. Try this:


Code:
foreach($suppliers as $row)
        {
        $tmp[] = array( $row->supplier_id => $row->supplier_name);
        }
    $data['options'] = $tmp;

I only tested this with print_r, but it should work with the dropdown. Also, if mld_supplier_get returns an array consisting only of ID and Name, you could just do:

Code:
$suppliers = $this->mdl_supplier->get();
    $data['options'] = $suppliers;

Regards,

Mike


Messages In This Thread
Dynamically fill an array from Mysql using Form Helper for dropdown list. - by El Forum - 10-19-2008, 07:36 AM



Theme © iAndrew 2016 - Forum software by © MyBB