Creating 7 selects with PHP and MySQL

1

I have a database and I want to fetch your content and display it within <select> 's, the initial one I get, I have 7 names in the database and I can display them all in the same select box, what I want now is to have 7 select's each with the 7 names, it would serve to choose the order in the future, I do not know if I made myself understand, the code I have now is this:

    <select name='listagem_dia'>
    <?php
    while ($dados = mysql_fetch_array($resultado)) {
        $nome = $dados["nome"];
        $id= $dados["id"];
        echo "<ul><li><option value=".$id.">".$nome."</option></li></ul>";
    }
    ?>
    </select>

It works just right that I can not duplicate the boxes depending on the number of results I have ... I have already managed to have the 7 boxes but only one name appears in each of them ... does anyone know how to duplicate the boxes above depending on the number of results?

    
asked by anonymous 29.07.2014 / 12:36

1 answer

1

If you want to display 7 SELECT's with the same results, you can do so

<?php
$db = mysql_connect('localhost', 'root', 'vertrigo');
$bd = mysql_select_db('cadastrosDados', $db);

$SQL = mysql_query("SELECT * FROM cadastros");

$opts = '';

while($exe = mysql_fetch_array($SQL)){

    $opts .= '<option value="'.$exe["nome"].'">'.$exe["nome"].'</option>';
}

for($i = 1;$i<=7;$i++){

    echo '<select>';
    echo $opts;
    echo '</select>';
}
?>

Here you will create a loop 7 times with the same select

    
29.07.2014 / 12:42