Popular PHP dropdown error with array

-1

Hello,

I have the following function that returns me the data needed to populate my dropdown:

    function listaRedes($conexao){
    $dados = array();

    $resultado = mysqli_query($conexao, "SELECT DISTINCT rede FROM evolucao_originacao");
    while($valores = mysqli_fetch_array($resultado)){
        array_push($dados, $valores);
    }
    return $dados;
};

And in my dropdown, I'm doing the following code:

 <?php $redesBanco = listaRedes($conexão); ?>
        <div class="form-group">
            <select class="form-control" id="dropdown-parceria">
                <option value="0">---SELECIONE---</option>
                <?php 
                    while($redesBanco){
                        echo "<option value='".$redesBanco."'>".$redesBanco."</option>";
                    }
                ?>
            </select>
        </div>

But at the time it populates my dropdown, the result is as follows:

    
asked by anonymous 02.12.2016 / 14:29

2 answers

0

use foreach to loop through the array:

<?php $redesBanco = listaRedes($conexão); ?>
            <div class="form-group">
                <select class="form-control" id="dropdown-parceria">
                    <option value="0">---SELECIONE---</option>
                    <?php 
                        foreach ($redesBanco as $chave){
                            echo "<option value='".$chave[0]."'>".$chave[1]."</option>";
                        }
                    ?>
                </select>
            </div>
    
02.12.2016 / 19:37
-2

Try to put $ banknotes [0]. Because you are trying to echo an array, it is recommended you give a var_dump to see the structure to write for example, <?php echo "<a href='".$redesBanco['link']."'>".$redesBanco['acesse']."</a>"; ?> But it can also be done the first way, informing the index with the number $ networksBanco [0]. In case your example should be done in a type like this ...:

<?php $redesBanco = listaRedes($conexão); ?>
    <div class="form-group">
        <select class="form-control" id="dropdown-parceria">
            <option value="0">---SELECIONE---</option>
            <?php 
                while($redesBanco){
                    echo "<option value='".$redesBanco[0]."'>".$redesBanco[1]."</option>";
                }
            ?>
        </select>
    </div>

I hope I have helped in some way

    
02.12.2016 / 14:43