I have a problem this is a part of my form, in my code I use select to make a catalog but I need you to take the values that were previously entered and that are stored in the corresponding tables of my BD in my case What I do is that I store them in my code (Enter an example of my code) <?php $options = ['Primero', 'Segundo', 'Tercero']; ?>
, what I need is that you do not need to write them in the code that takes them direct from the database and respects them in the select .
In my main table "worker" where the records are being inserted are foreign keys and I only take the IDs of each table ie in my table "worker" I have the fields idctg_nomina and in my second table "nomina" where I have my foreign key "idctg_nomina" and descripcion_nomina what I want is that insert by ID but not by description since my values in my BD are INT type.
How do I make it respect the data of the select that had previously been entered and when saving respect those fields?
<h2> Administración de Trabajadores Registrados</h2>
<div class="well well-small">
<hr class="soft"/>
<h4>Edición de Trabajadores Registrados</h4>
<div class="row-fluid">
<?php
extract($_GET);
require("connect_db.php");
$sql="SELECT * FROM trabajador WHERE id_control=$id_control";
//la variable $mysqli viene de connect_db que lo traigo con el require("connect_db.php");
$ressql=mysqli_query($mysqli,$sql);
while ($row=mysqli_fetch_row ($ressql)){
$id_control=$row[0];
$nombre=$row[1];
$ap_paterno=$row[2];
$ap_materno=$row[3];
$NSS=$row[4];
$CURP=$row[5];
$RFC=$row[6];
$id_puesto=$row[7];
$id_area=$row[8];
$idctg_turno=$row[9];
$idctg_empresa=$row[10];
$id_nomina=$row[11];
}
?>
<form action="ejecutaactualizar_trabajador.php" method="post">
No. Control:<br><input type="text" name="id_control" value= "<?php echo $id_control?>" readonly="readonly"><br>
Nombre:<br> <input type="text" name="nombre" value="<?php echo $nombre?>"><br>
Apellido Paterno:<br> <input type="text" name="ap_paterno" value="<?php echo $ap_paterno?>"><br>
Apellido Materno:<br> <input type="text" name="ap_materno" value="<?php echo $ap_materno?>"><br>
NSS:<br> <input type="text" name="NSS" value="<?php echo $NSS?>"><br>
CURP:<br> <input type="text" name="CURP" value="<?php echo $CURP?>"><br>
RFC:<br> <input type="text" name="RFC" value="<?php echo $RFC?>"><br>
Puesto:<br> <input type="text" name="id_puesto" value="<?php echo $id_puesto?>"><br>
Area:<br> <input type="text" name="id_area" value="<?php echo $id_area?>"><br>
Turno:<br> <input type="text" name="idctg_turno" value="<?php echo $idctg_turno?>"><br>
Empresa:<br> <input type="text" name="idctg_empresa" value="<?php echo $idctg_empresa?>"><br>
Tipo Nómina:<br>
<select>
<?php
foreach ($options as $option) {
if ($option=== $id_nomina) {
echo '<option selected="selected" value='.$option.'>'.$option.'</option>';
} else {
echo('<option value='.$option.'>'.$option.'</option>');
}
}
?>
</select>
<br>
<input type="submit" value="Guardar" class="btn btn-success btn-primary">
</form>