Fuelphp: populate data in database to dropdown

359 views Asked by At

I have a dropdown and I want that inside of it, is the data from database. The dropdown is working a little bit fine. But the problem is I have 2 data in the database but it only display only 1 data.

This is my code in my view.php:

<h4>Choose Deck: </h4><?php  foreach ($models as $key=>$value);
    echo Form::select('country', 'none', array(
        ' ' => '',
        $value['id'] => $value['deckname'] 
    ));
?>

And the display is here: form output

As you can see in the picture I do have 2 data but it only shows one.What is wrong with my code? Any suggestions please

1

There are 1 answers

0
mark.sagikazar On BEST ANSWER

Ah, got it. The problem is that you are doing two selects with the same name. Since the second item is the last, it will only been shown because it overwrites everything else (with the same name).

Do something like this:

<h4>Choose Deck: </h4>
<?php

$select = array();

foreach ($models as $key => $value)
{
    $select[$value['id']] = $value['deckname'];
}

array_unshift($select, '');

echo Form::select('country', 'none', $select);

?>