Edit table with corresponding value <select>

Asked

Viewed 40 times

0

I have a form to edit the table data, it is working normally. But when loading the page is searching for the last name of the table.

I would like to know a way to load the page, come already selected the value corresponding to the data of that table.

The relations are right, Insert, delete and even update. However when I edit, instead of searching for the name of the position corresponding to the employee it looks for the last position. See: inserir a descrição da imagem aqui

inserir a descrição da imagem aqui

I’m trying to do the if but it didn’t work out too well...

I added the condition to the code, if the cargo_id (Work Table) is equal to id_position (Position Table)

<?php if( $linha['cargo_id'] == $lista['id_cargo']){?>selected<?php } ?>

I did so:

<select class="form-control" name="cargo_id">
    <?php 
    while($linha = mysqli_fetch_array($consulta_cargo,$consulta_func)){
      ?>
    <option value="<?php echo $lista['id_cargo']?>" <?php if( $linha['cargo_id'] == $lista['id_cargo']){?>selected<?php } ?>> <?php echo $lista['nome_cargo']?></option>
        <?php
    }
        ?>
</select>
  • Place: <option><?php echo $lista['nome_cargo']." - ".$linha['cargo_id']."/".$lista['id_cargo']?></option> and see if the option that should be selected shows the values $linha['cargo_id'] and $lista['id_cargo'] equal. For example: Financeiro - 12/12 (assuming the "Financial" id is "12").

  • Although it is strange, if the if failed, the first option is that it should appear selected. See in the source code if options appear selected. If all options have selected, the latter will be selected.

  • <option><? php echo $list['job name']." - ". $line['job name']." /". $list['job name']? ></option> did not show anything either...

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.