Edit select by displaying bank value and showing other table options

Asked

Viewed 988 times

2

I have the table that registers a user (gr_entity) and has a link with a user status table (gr_entidade_status). I want the editing form (editando_user.php) to show the value that is in the database, but allow me to see the other items that are in the table (gr_entidade_status) so I can edit.

Note: The connection to the database and post method is working perfectly.

Below is the select that picked the user to present his information

 $sql = " SELECT * FROM gr_entidade ent
         JOIN gr_entidade_status status on ent.id_entidade_status = status.id_entidade_status
         JOIN gr_entidade_tipo tipo on ent.id_entidade_tipo = tipo.id_entidade_tipo WHERE id_entidade =  " . $_GET['id'];
$conn = mysql_query($sql);
$usuario = mysql_fetch_array($conn);

Then the $user variable along with the field I define, appears the value that is in the database. In the case for this code would be value ='<?php echo $usuario ['id_entidade_tipo'] ?>'

Below follows the status field. In this case, I made a select exclusively in the status table (gr_entidade_status) to give me the value of the name (status)

  <label class="control-label">*Staus</label>
     <select class="form-control" name="id_entidade_status">
        <?php
           $result = mysql_query("SELECT * FROM gr_processo_status");
               while ($row = mysql_fetch_array($result)) {                               
         ?>
          <option value="<?php echo $row['id_status_processo']?>"> <?php echo $row['status']?></option>
          <?php
                 }
             ?>
   </select>

I wonder how I can do to be executed properly

  • I recommend migrating to mysqli, since mysql has become obsolete in newer versions of php: https://answall.com/questions/579/por-que-n%C3%A3o-devo-usar-fun%C3%A7%C3%B5es-do-tipo-mysql

  • But how would I use the current version? Because I can’t change yet, I have to restructure everything.

  • It will be almost the same, there are few changes. I recommend taking a look at the official documentation of php.

  • There is a "soup" of letters, it is not clear what you want. From what I understand you want to show all the status of existing processes, in an html select tag, and then leave selected a specific status. Only the part $usuario ['id_entidade_tipo'] does not seem to have any relation. Need to detail better.

  • This field is inside the gr_entity table , which receives the status code.

  • Please disregard this field with the type information, consider it as if it were id_entidade_status

Show 1 more comment

1 answer

1


I managed by executing the following form:

 <select class="form-control" name="id_entidade_tipo">
                                                        <?php
                                                          $result = mysql_query("SELECT * FROM gr_entidade_tipo");
                                                          while ($row = mysql_fetch_array($result)) {                               
                                                          ?>
                                                        <option value="<?php echo $row['id_entidade_tipo']?>" <?php if( $usuario['id_entidade_tipo'] == $row['id_entidade_tipo']){?>selected<?php } ?>> <?php echo $row['tipo_entidade']?></option>
                                                         <?php
                                                         }
                                                         ?>
                                                    </select>

Browser other questions tagged

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