Bring the value of the select and leave it marked by GET

1

Good I'm doing the order editing and I bring the data through GET. There is a field in the table called Iduser which is the user who has placed the order.

Then to edit the order I get a select with all the users that I have in the BD.

<select id="select2-1" value="" class="form-control selectSegundo" name="select2-1" style="min-height: 38px;">
   <option value="0">Seleciona un cliente</option>
   <?php
     $resultisa = $mysqli->query("SELECT * FROM Usuarios");
     mysqli_set_charset("utf8");
     while($resia = $resultisa->fetch_array()) {
   ?>
     <option value="<?php echo $resia['IdUsuario'] ?>"><?php echo $resia['Nombre'] ?></option>
    <?php } ?>
</select>

I would like this user to select the user that comes through GET, but with the possibility of changing the user for another one.

Any ideas ??? Thanks

    
asked by Miguel 11.12.2018 в 10:15
source

1 answer

0

You can make a conditional and compare each value that comes from the Users table. Let's suppose that the value of the GET you receive it like this:

// No está sanitizado el GET es un paso que debes hacer, pero por cuestiones de explicación:
 $IdUsuarioGet = $_GET["IdUsuario"]; 

<select id="select2-1" value="" class="form-control selectSegundo" name="select2-1" style="min-height: 38px;">
 <option value="0">Seleciona un cliente</option>
   <?php
   $resultisa = $mysqli->query("SELECT * FROM Usuarios");
   mysqli_set_charset("utf8");
   while ($resia = $resultisa->fetch_array()) {
   ?>       
    <option value="<?php echo $resia['IdUsuario'] ?>" <?php if ($IdUsuarioGet == $resia['IdUsuario']) {
    echo "selected='selected'";} ?>><?php echo $resia['Nombre'] ?></option>
   <?php } ?>
  </select>
    
answered by 11.12.2018 в 16:49