Appear table after filling fields and press button

Asked

Viewed 35 times

1

I have the following table:

 <table width="100%" class="table table-bordered table-hover table-responsive table-striped" id="empenho_solicitante">  
    <thead>
        <tr>       
             <th>Empenho</th>
             <th>Programatica</th>
             <th>Conta Desp.</th>
             <th>Credor</th>
             <th>Valor</th>
        </tr>
  </thead>
  <tbody>
       <?php  
            while ($linha = sqlsrv_fetch_array($resultado))
            {
            ?>
                 <tr class="odd gradeA">
                 <td align = "right"> <?php echo $linha["num_empenho"]; ?> </td>
                 <td align = "center"><?php echo $linha["programatica"];?> </td>
                 <td align = "center"> <?php echo $linha["conta_desp"]; ?> </td>
                 <td align="left"><?php echo $linha["nome_fornecedor"]; ?> </td>
                 <td align = "right"> <?php echo 
                        number_format($linha["valor_empenhado"], 2, ',', '.'); 
                        $total +=  $linha["valor_empenhado"]; ?> </td>
                 </tr>
            <?php                                       
            }
            ?>                                        
            <td colspan="4" align = "middle"> <?php echo "Valor empenhado para este solicitante no período:" ?> </td>
            <td> <?php echo number_format($total, 2, ',', '.'); ?> </td>                                   
      </tbody>
</table>

And I also have a select, I would like them to appear only after filling 4 fields and a "query" button was pressed, follow the form with these elements:

<form method="post" action="">
    Início do período:
    <input type="text" id="calendarioIni" name="dataInicio">
    Fim do período:
    <input type="text" id="calendarioFim" name="dataFim">
    <br><br><br>
    <span class="IWLABEL11CSS" id="IWLABEL7">Órgão: </span>
    <select name="Distrito" size="1" width="180" class="COMBODISTCSS" id="COMBOFAB" tabindex="1">
        <option value="01">Gabinete do Prefeito</option>
        <option value="02">Coordenadoria de Governo e Comunicação Social</option>
        <option value="03">Secertaria Municipal de Planejamento</option>
        <option value="04">Procuradoria Jurídica</option>
        <option value="05">Ouvidoria Municipal</option>
        <option value="06">Secretaria Municipal de Administração</option>
        <option value="07">Secretaria Municipal da Fazenda</option>
        <option value="08">Auditoria Interna</option>
        <option value="09">Secretaria Municipal de Obras</option>
        <option value="10">Secretaria Municipal de Desenvolvimento Urbano e Meio Ambiente</option>
        ...
        </select>

    <span class="IWLABEL11CSS" id="IWLABEL7">Unidade: </span>
    <select name="Concelho" size="1" width="195" class="COMBOCONCCSS" id="COMBOCID" tabindex="1">
         <option data-distrito="01" value="01">Gabinete do Prefeito</option>
         <option data-distrito="01" value="02">Departamento de Assuntos Institucionais</option>
         <option data-distrito="02" value="03">Gabinete da Coordenadoria de Governo e Comunicação Social</option>
         <option data-distrito="02" value="04">Departamento de Comunicação Social</option>
          <option data-distrito="02" value="05">Administração Distrital de Ipoema</option>
         <option data-distrito="02" value="06">Administração Distrital de Senhora do Carmo</option>
         <option data-distrito="03" value="07">Gabinete da Secretaria Municipal de Planejamento</option>
         <option data-distrito="03" value="08">Departamento de Orçamento Municipal</option>
         <option data-distrito="03" value="09">Departamento de Estudos e Avaliação</option>
         ...
    </select>
    <br><br>

    <input type="submit" id="consultar" value="Consultar" />
    <br><br><br>

     <?php if(isset($_POST['dataInicio']) && isset($_POST['dataFim']))
           {
                  $dataIni = $_POST['dataInicio'];
                  $dataIni = str_replace("/", "-",$dataIni);
                  $dataIni = date('Y-m-d', strtotime($dataIni));
                  $dataFim = $_POST['dataFim'];
                  $dataFim = str_replace("/", "-",$dataFim);
                  $dataFim = date('Y-m-d', strtotime($dataFim));
                  $cod_orgao = $_POST['Distrito'];
                  $cod_unidade = $_POST['Concelho'];
                  echo $dataIni."<br>";//Teste para verificar o valor nas variáveis
                  echo $dataFim."<br>";
                  echo $cod_orgao."<br>";
                  echo $cod_unidade."<br>";
           } 
           ?>                                    
</form>
  • If your table will be populated with data coming from the server as a result of the query made in the form, you will need to do an ajax post and popular table by javascript or a simple post that would result in a "refresh" of the page.

  • i am already making this post simple with the refresh of the page, but I would like the table only to appear mediate the pressing of the button "consult" .

  • You can return a variable just for that or add an if before the table by checking if the $result has some value.

1 answer

1


You can simply check if the page is the result of a post.

<?
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
?>
    <table width="100%" class="table table-bordered table-hover table-responsive table-striped" id="empenho_solicitante">  
<thead>
    <tr>       
        <th>Empenho</th>
        <th>Programatica</th>
        <th>Conta Desp.</th>
        <th>Credor</th>
        <th>Valor</th>
    </tr>
</thead>
<tbody>
<?php  
    while ($linha = sqlsrv_fetch_array($resultado))
    {
    ?>
        <tr class="odd gradeA">
        <td align = "right"> <?php echo $linha["num_empenho"]; ?> </td>
        <td align = "center"><?php echo $linha["programatica"];?> </td>
        <td align = "center"> <?php echo $linha["conta_desp"]; ?> </td>
        <td align="left"><?php echo $linha["nome_fornecedor"]; ?> </td>
        <td align = "right"> <?php echo 
            number_format($linha["valor_empenhado"], 2, ',', '.'); 
            $total +=  $linha["valor_empenhado"]; ?> </td>
        </tr>
    <?php                                       
    }
    ?>                                        
    <td colspan="4" align = "middle"> <?php echo "Valor empenhado para este solicitante no período:" ?> </td>
    <td> <?php echo number_format($total, 2, ',', '.'); ?> </td>                                   
</tbody>
</table>
<? } ?>

Browser other questions tagged

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