phpredbean

How to populate rows from MySQL to dropdown menu using RedbeanPHP


please help me to populate rows from MySQL to dropdown menu.

$result = R::getCol("SELECT name FROM language");

I see all beans, but how can I put this beans into dropdown menu and can send multiple values to MySQL?

<select name="languages">
?????
</select>

Thanks!


Solution

  • That returns an array of values, so a simple foreach should process that nicely

    See The RedBeansPHP Manual

    $names = R::getCol("SELECT name FROM language");
    
    echo '<select name="languages">';
    
    foreach( $names as $name ) {
        echo "<option value='$name'>$name</option>";
    }
    
    echo '</select>';