Drop down list with PDO [closed]

0

Good morning, I'm trying to get the data in a combo and I do not know if something fails me, you should show me the fixed options.

$pdo = new PDO('mysql:host=localhost;dbname=prueba', 'root', '');
$sql = "SELECT acro_subcategoria FROM tipodocumentos";
$stmt = $pdo->prepare($sql);
$stmt->execute();
$tipodocumentos = $stmt->fetchAll();

And this would be the select

<select>
<?php foreach ($tipodocumentos as $acro_subcategoria): ?>
<option value="<?= $acro_subcategoria['acro_subcategoria']; ?>"></option>
<?php endforeach; ?>
</select>
    
asked by Alberto Cepero de Andrés 18.04.2017 в 11:05
source

1 answer

1

Except for my mistake, you have the wrong php opening in the following line:

Try changing

<option value="<?= $acro_subcategoria['acro_subcategoria']; ?>"></option>

for

<option value="<?php $acro_subcategoria['acro_subcategoria']; ?>"></option>
    
answered by 18.04.2017 / 11:30
source