Creating a SELECT based on another SELECT

Asked

Viewed 408 times

2

I am using a SELECT that automatically updates the page after it is selected. I created another SELECT to work based on the previous SELECT, however, although I see the right amount of registration, nothing is written.

$bandorc = isset($_GET['bandorc'])?$_GET['bandorc']:"";
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="30%">
      <form method="get" name="tBand" id="cBand" style="float:left;margin-top:0px;">
        <select name="menu1" onChange="MM_jumpMenu('parent',this,0)">
            <option value="">Selecione a Bandeira</option>
<?php
      $qry="SELECT sjy_empresas.bandeira AS id_bandeira,     
            sjy_bandeira.bandeira
            FROM kcb_tbstates 
            INNER JOIN sjy_bandeira 
            INNER JOIN sjy_grupo 
            INNER JOIN sjy_empresas ON sjy_grupo.id_grupo = sjy_empresas.grupo
            AND sjy_bandeira.id_bandeira = sjy_empresas.bandeira
            AND kcb_tbstates.ID = sjy_empresas.estado
            WHERE sjy_empresas.grupo = '$grupo'
            GROUP BY sjy_empresas.bandeira, sjy_bandeira.bandeira";
      // Executa a consulta OU mostra uma mensagem de erro
      $rs = $MySQLi->query($qry) OR trigger_error($MySQLi->error, E_USER_ERROR);

      // Faz um loop, passando por todos os resultados encontrados              
      while ($dt        = $rs->fetch_object()) {
            $band       = $dt->id_bandeira;
            $bandeira   = $dt->bandeira;


            echo "<option value='premorc.php?fnc=". $fnc . "&ans=" . $linha . "&bandorc=" . $band . "'>" . $bandeira . "</option>";
    }
?>  
            </select> 
      </form>
    </td>
    <td width="*">      
      <form method="get" name="tLoja" id="cLoja" style="float:left; padding-left:15px;margin-top:0px;">
        <select name="menu2" onChange="MM_jumpMenu('parent',this,0)">
            <option value="">Selecione a loja</option>
            <?php   
    $sql="SELECT 
            sjy_empresas.id_empresa, 
            sjy_empresas.nick, 
            sjy_empresas.bandeira AS band, 
            sjy_bandeira.bandeira
          FROM sjy_bandeira 
          INNER JOIN sjy_empresas ON sjy_bandeira.id_bandeira = sjy_empresas.bandeira
            WHERE sjy_empresas.grupo = $grupo
            AND id_bandeira = $bandorc";
      // Executa a consulta OU mostra uma mensagem de erro
      $rset = $MySQLi->query($sql) OR trigger_error($MySQLi->error, E_USER_ERROR);

      // Faz um loop, passando por todos os resultados encontrados              
      while ($dt        = $rset->fetch_object()) {
            $empr       = $rset->id_empresa;
            $nick       = $rset->nick;
            echo    "<option value='premorc.php?fnc=". $fnc . "&ans=" . $linha . "&emp=" . $lj . "'>" . $nick . "</option>";
            }

            ?>

            </select>           
        </form>
        </td>
  </tr>
</table>

    <form action="../inc/processa.php" method="post">
        <input name="emp" type="text" value="<?php echo $empr; ?>" /> - Filial da Premissa: <?php echo $nick; ?>

    </form>
  • Which one is coming empty?

  • The second SELECT and input

  • The values in value appear in the source code?

  • I didn’t quite understand the question, but when selecting the first SELECT, the one that selects the flag, the url looks like this: http://localhost/final/views/premorc.php? fnc=gfi&ans=14&bandorc=47

  • You said it returns the right amount of record. All select options appear but are left without text?

  • Exactly that

  • See if the answer I put solves.

Show 2 more comments

1 answer

0


If problem is in this part of the code:

while ($dt        = $rset->fetch_object()) {
    $empr       = $rset->id_empresa;
    $nick       = $rset->nick;
    echo    "<option value='premorc.php?fnc=". $fnc . "&ans=" . $linha . "&emp=" . $lj . "'>" . $nick . "</option>";
}

Change the reference $rset for $dt by assigning database values to the respective variables:

while ($dt        = $rset->fetch_object()) {
    $empr       = $dt->id_empresa;
    $nick       = $dt->nick;
    echo    "<option value='premorc.php?fnc=". $fnc . "&ans=" . $linha . "&emp=" . $lj . "'>" . $nick . "</option>";
}

Browser other questions tagged

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