Return Bank Data and List in Combobox

0
Hello, I would like to be able to return the values from the table bank of the company and for each line that returns going to create an option in the combobox, I would like to know how to do this, I think it should be with while or for each, help to set up.

Comboxbox code:

<div class="profile-info-row">
<div class="profile-info-name"> Empresa </div>  

<div class="profile-info-value">
    <select name="empresa_destino" id="form-field-1" class="col-xs-11 col-sm-6 col-md-8">
        <option value="">Selecione a Empresa</option>
        <option value="1">Emp1</option>
        <option value="2">Emp2</option>
        <option value="3">Emp3</option>
    </select>
</div>
</div>

PHP code to return bank values:

<?php
    session_start();

    if (!isset($_SESSION["logado"]) || $_SESSION["logado"] != TRUE) {
        header("Location: login.html");
    }

        include "conexao.php";
        include "executaSQL.php";

        $SQL = "SELECT cod_empresa , razao_social FROM 'tbl_empresa'";

        $link= conectar ();
        $inserido = executaSQL($SQL, $link);

?>

EDIT:

I was able to adjust this code of mine:

    <div class="profile-info-value">
                                        <?php
    include "conexao.php";
    include "executaSQL.php";

    $link=conectar(); 

    $busca_query = mysql_query("SELECT cod_empresa,razao_social FROM tbl_empresa")or die(mysql_error());
?>                                        
                                            <select name="empresa_destino" id="form-field-1" class="col-xs-11 col-sm-6 col-md-8">
                                                <option value="" selected disabled="disabled" hidden>Selecione a Empresa</option>

                                                <?php while ($dados = mysql_fetch_array($busca_query)) { ?>

                                            <option value="<?php echo $dados['cod_empresa']; ?>"><?php echo $dados['razao_social']; ?></option> <?php } ?>

                                            </select>
                                        </div>
    
asked by anonymous 10.02.2017 / 12:40

2 answers

0

Resolution code I used:

<div class="profile-info-value">
                                        <?php
    include "conexao.php";
    include "executaSQL.php";

    $link=conectar(); 

    $busca_query = mysql_query("SELECT cod_empresa,razao_social FROM tbl_empresa")or die(mysql_error());
?>                                        
                                            <select name="empresa_destino" id="form-field-1" class="col-xs-11 col-sm-6 col-md-8">
                                                <option value="" selected disabled="disabled" hidden>Selecione a Empresa</option>

                                                <?php while ($dados = mysql_fetch_array($busca_query)) { ?>

                                            <option value="<?php echo $dados['cod_empresa']; ?>"><?php echo $dados['razao_social']; ?></option> <?php } ?>

                                            </select>
                                        </div>
    
10.02.2017 / 17:05
0

The solution itself has already spoken: use some loop structure ( while , foreach , for ).

You did not say what executarSQL returns.

Assuming you return a array , the code should look like this:

<select name="empresa_destino" id="form-field-1" class="col-xs-11 col-sm-6 col-md-8">
    <option value="">Selecione a Empresa</option>

    <?php foreach ($inserido as $codigo => $valor): ?>
    <option value="<?php echo $codigo ?>"><?php echo $valor ?></option>
    <?php endforeach; ?>
</select>

See the PHP of the Right Way guide and the man page to learn more about modern PHP.

    
10.02.2017 / 13:14