0
I have the following situation: I have a simple example of a form to display a bank’s information to change and then record it again. In this case the problem is in NOME_OPERADOR, where I wanted to already have set the value that is written in the bank, but to offer in a Selct the options in case you want to change the operator responsible for a given task. As the code below, if I take the WHILE excerpt, It is bringing right the operator recorded in the bank, but when I put the WHILE to take the table other operators, brings me all operators (As I wish), however I wanted to know the possibility of first (selected) the operator already recorded in the bank related to this activity. That would be more or less the doubt (Sorry if it got a little confused). NOTE: I have a OPERATORS TABLE, and a ACTIVITIES TABLE, where only the OPERATOR COD is stored.
$resultado = mysql_query("select * from atividades
INNER JOIN operadores on cod_operador=codoperador_atividade
where COD_ATIVIDADE = $id");
$dados = mysql_fetch_array($resultado);
$reoperador = mysql_query("SELECT * FROM operadores c WHERE c.codfuncao_operador=2 order by nome_operador");
<TRECHO DO FORM HTML>
<select selected="selected" class="form-control" name="nome_operador" id="nome_operador" class="textBox" value="<?php echo $dados["NOME_OPERADOR"]; ?>">
<?php
while($l = mysql_fetch_array($reoperador)) {
$id = $l["COD_OPERADOR"];
$nome = $l["NOME_OPERADOR"];
$email = $l["EMAIL_OPERADOR"];
//faz a comparação do operador selecionado com demais itens da lista
$selected = ($id == $dados['COD_OPERADOR']) ? 'selected="selected"' : '';
//escreve a option
printf('<option value="%d" %s>NOME:%s - E-MAIL: %s</option>',$id, $selected, $nome, $email);
}
mysql_close();
?>
</select>
I adjusted but returned the same results, all OPERATORS. While I have echo in this structure: echo "<option value="$id">COD: $id PROJETO: $nome CLIENT: $email</option> n"; I can adapt the printf to echo?
– TiagoIB
When you give a blank page, add these two lines at the beginning of the script,
ini_set('display_errors', true); error_reporting(E_ALL);
what is the name of the id field of$reoperador
? @Tiagoib– rray
The field name is COD_OPERADOR. It would be the name in the OPERATORS TABLE?
– TiagoIB
Would that be to include the Selected tag? <select Selected="Selected" class="form-control" name="operator name" id="operator name" class="textbox" value="<? php echo $data["NOME_OPERADOR"]; ?>">
– TiagoIB
@Tiagoib saw the edition?
– rray
I changed the code of the question according to what you suggested, take a look. @rray
– TiagoIB
Which edition you refer to?
– TiagoIB
I had put the name of the wrong variable, the right one was
$dados
. @Tiagoib.– rray
I adjusted again the Code of the above question. However, it continues to bring only operators. It’s like I haven’t been getting the tag: Selected="Selected". @rray
– TiagoIB
Worked, needed to reload previous page. @rray
– TiagoIB