I have a table "put" this table contains the following fields
id puesto
1 empleado
2 director
3 programador
already having the ID correcpondiente to the user and the data contained by a submith in $id = $_GET['id'];
I want my select field to show its value according to the one that corresponds to the user, example:
if John has the "user" table in the "field" field, the id = 2, that the select shows:
<option value="<?php echo $id; ?>"><?php echo $p['puesto']; ?></option>
or translated
<option value="2">director</option>
To achieve this, and investigated the following:
<?php
$tabla_puesto =sqlsrv_query($conn, "select * from puesto");
//$conn contiene la conecion a la base de datos
$id = $_GET['id'];
//aqui obtengo el id que corresponde al usuario en este caso seria usuario=2
$sql_usuario= "SELECT * FROM usuario WHERE Id=$id ORDER BY Id ASC";
//consulta select para identificar BD
$result = sqlsrv_query($conn, $sql_usuario);
while($res = sqlsrv_fetch_array($result))
{
$puesto=$res['puesto'];
//muestro el valor de pesto
$sql_puesto = sqlsrv_query($conn, "select * from puesto where id=$puesto");
if($c=sqlsrv_fetch_array($sql_puesto)) {
$tabla_puesto_puesto=$c['puesto'];
}
}
//aqui seleciono la tabla puesto y relaciono que el valor de id con el valor del puesto corespondiente a su id de puesto, igualamos y consegumos el puesto con $tabla_puesto_puesto
?>
at this point I already have $ table_posed_post = director
the select where I want the position to appear in the selection this is my real problem is the following:
<select>
<?php foreach($tabla_puesto as $p):?>
<option value="<?php echo $p['id']; ?>">
<?php echo $p['puesto']; ?>
</option>
<?php endforeach; ?>
</select>
This select does not work but I would like to know what the error is or if there is some simpler way, I hope I have described my problem correctly