0
Hello, I would like to be able to return the values of the company table database and for each row that returns go creating an option in the combobox, I would like to know how to do this, I think should be with while or for each, but would like help to assemble.
Code of the Comboxbox:
<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 database 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 managed to adjust that 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>
it is important that you learn to use the standard library PDO or mysqli. the functions
mysql_*
were discontinued in PHP 5.5 and in version 7.0 it ceased to exist. To ensure that your programs will work in updated versions of PHP, start migrating.– lucasvscn