Récupération d'une liste de donnée en php

Résolu
Bonjour,

voici mon petit souci, je débute en php orienté objet et je suis bloqué sur la récupération de donnée via un formulaire select.

voici ma fonction php :
<?php

function getOptions() {
return array(
array('value' => '0', 'text' => '---'),
array('value' => '1', 'text' => 'Boucle du Mouhoun'),
array('value' => '2', 'text' => 'Cascades'),
array('value' => '3', 'text' => 'Centre'),
array('value' => '4', 'text' => 'Centre-Est'),
array('value' => '5', 'text' => 'Centre-Nord'),
array('value' => '6', 'text' => 'Centre-Ouest'),
array('value' => '7', 'text' => 'Centre-Sud'),
array('value' => '8', 'text' => 'Est'),
array('value' => '9', 'text' => 'Hauts-Bassins'),
array('value' => '10', 'text' => 'Nord'),
array('value' => '11', 'text' => 'Plateau-Central'),
array('value' => '12', 'text' => 'Sahel'),
array('value' => '13', 'text' => 'Sud-Ouest'),

);
}

et voici mon code html du formulaire :

<?php
require_once('php/functions.php');
/*
* Retourne la liste des options et leurs valeurs
*/
$options = getOptions();
?>

<form action="POST">
<label class="cb">ARCHITECTES CONCEPTEURS</label>
<input type="text" class="input" required/>
<br><br>
<label class="cb">AGGLOMERATION</label>
<input type="text" class="input" required/>
<br><br>
<label class="cb">REGIONS</label>
<select>
<option value="<?php echo getOptions(3); ?>" selected="selected">
<?php
foreach ($options as $key => $value) {
echo $value;
}
?>
</option>
</select>
<br><br>
<input type="submit" class="submit" value="RECHERCHER">
</form>


Or sa me fait pleins d'erreur et je suis un peut perdus au niveau de ma boucle T_T help me plz

2 réponses

  1. Salut,

    Essaye comme ceci :
    <select>
    <?php
    $options = getOptions();
    foreach ($options as $option) {
    ?>
        <option value="<?php echo $option['value']; ?>"><?php echo $option['text']; ?></option>
    <?php } ?>
    </select>
    


    Bonne journée
    1
    1. Super génial merci j'y étais presque arrivé solo il y a 2min
      0