Mysql
 sql >> Base de Dados >  >> RDS >> Mysql

Mostrando valores suspensos separados por vírgulas da coluna no banco de dados


Tente usar isso, conforme necessário, program valores da coluna:
<?php
$pdo = Database::connect();
$sql="SELECT t1.*, t2.*
    FROM form_fields t1, user_choices t2
    WHERE t1.field_name = t2.field_name
    and group_id=1 and user_id=".$_SESSION['user_id']." ";
//$result = $pdo->query($sql);

echo '<select class="form-control" name="program">';
foreach ($pdo->query($sql) as $row_program){
    $options = $row_program['program'];// as you need this column values
    $optionsArr = explode(",", $options);   
    foreach ($optionsArr as $key=>$row){
        echo '<option value='.$row[$key].'>'.$row[$key].'</option>'; 
    }
}
echo '</select>';
?>