Do not take the direct values from my Database my Select

0

Realize my BD with my main table "worker", and depend others of her an example is my table "nomina" with the fields: id_nomina and descripcion_nomina , what I intend with this is that it is inserted or modified through the ID and that it shows the interface the description, up to this point I do not have any problem since it does it.

My problem is the following one, this is a part of my form to modify the registries, that is to say if I previously enter "Biweekly" (with id_nomine = 2) I want that when accessing my module of modifications it appears to me by delfaul in my select the value that I insert that would be "Biweekly" the problem I have is that I do not appear that I insert, I see the first record that is registered in my table "nomina" ("Weekly = 1 ") , I do not respect the values that were previously inserted in the BD.

How do I make it respect the data of the select that had previously been entered and when saving respect those fields?

		
		<?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>
				



<label>Tipo de Puesto</label>
<?php
require("connect_db.php");

$query = "SELECT DISTINCT id_puesto, descripcion_puesto FROM puesto";
$res = $mysqli->query($query);
$option = '';
while ($row = $res->fetch_assoc()){

    $option.="<option value=\"$row[id_puesto]\">$row[descripcion_puesto] </option>";   
   
}
?>

					
<select type="text"  id="id_area" name="id_area" placeholder="Area" required>

<?php echo $option; ?>
</select>



				
	


<label>Tipo de Área</label>
<?php
require("connect_db.php");

$query = "SELECT DISTINCT id_area, descripcion_area FROM area";
$res = $mysqli->query($query);
$option = '';
while ($row = $res->fetch_assoc()){

    $option.="<option value=\"$row[id_area]\">$row[descripcion_area] </option>";   
   
}
?>

					
<select type="text"  id="id_area" name="id_area" placeholder="Area" required>

<?php echo $option; ?>
</select>

	
		
<label>Tipo de Turno</label>
<?php
require("connect_db.php");

$query = "SELECT DISTINCT idctg_turno, descripcion FROM ctg_turno";
$res = $mysqli->query($query);
$option = '';
while ($row = $res->fetch_assoc()){

    $option.="<option value=\"$row[idctg_turno]\">$row[descripcion] </option>";   
   
}
?>
				
<select type="text"  id="idctg_turno" name="id_ctg_turno" placeholder="Turno" required>

<?php echo $option; ?>
</select>
				






				
<label>Tipo de Empresa</label>
<?php
require("connect_db.php");

$query = "SELECT DISTINCT idctg_empresa, descripcion_empresa FROM empresa";
$res = $mysqli->query($query);
$option = '';
while ($row = $res->fetch_assoc()){

    $option.="<option value=\"$row[idctg_empresa]\">$row[descripcion_empresa] </option>";   
   
}
?>

					
<select type="text"  id="id_empresa" name="id_empresa" placeholder="Empresa" required>

<?php echo $option; ?>
</select>





	
				
			

<label>Tipo de Nómina</label>
<?php
require("connect_db.php");

$query = "SELECT DISTINCT id_nomina, descripcion_nomina FROM nomina";
$res = $mysqli->query($query);
$option = '';
while ($row = $res->fetch_assoc()){

    $option.="<option value=\"$row[id_nomina]\">$row[descripcion_nomina] </option>";   
   
}
?>

					
<select type="text"  id="id_nomina" name="id_nomina" placeholder="Nomina" required>

<?php echo $option; ?>
</select>
				
				
				
				
				
				
				
				
				
				
				<br>
				<input type="submit" value="Guardar" class="btn btn-success btn-primary">
			</form>

				  
		
		
		<div class="span8">
		
		</div>	
		</div>	
		<br/>

	
  </body>
</html>
    
asked by Carlos 02.03.2018 в 15:17
source

1 answer

0

I'll give you an example in one of the blocks so you can see the idea.

Having the initial declarations $ id_posed = $ row [7];

<label>Tipo de Puesto</label>
<?php
    require("connect_db.php");

    $query = "SELECT DISTINCT id_puesto, descripcion_puesto FROM puesto";
    $res = $mysqli->query($query);
    $option = '';
    while ($row = $res->fetch_assoc()){
        if($id_puesto == $row["id_puesto"]) {
            $option.="<option selected value='".$row["id_puesto"]."'>".$row["descripcion_puesto"]."</option>";
        } else {
            $option.="<option value='".$row["id_puesto"]."'>".$row["descripcion_puesto"]."</option>";
        }

    }
?>

What I do is identify the worker's record by means of its id and when it matches, I show the option with a attribute selected that will leave it marked or selected.

    
answered by 02.03.2018 в 17:11