Store select value fed by SQL and change the WHERE query

Asked

Viewed 111 times

-2

I need the user to select a date in the combo box, change the value of the variable corresponding to the period in WHERE, to show the table only of the corresponding period.

SELECT

<select id="data">
  <?php
    $data = mysql_query("SELECT DISTINCT `periodo` FROM `informatica_relatorio`") or die(mysql_error());

    while ($row = mysql_fetch_array($data))
    {
    echo '<option>'.$row['periodo'].'</option>';
    }
  ?>
</select>           
<input type="submit" value="OK"/> <!-- Botão para confirmar o período -->

In another PHP file I have the following part that needs to have the value changed.

$dfbruto = mysql_query("SELECT SUM(valor) FROM informatica_relatorio WHERE `empresa` = 'DF' AND **VARIÁVEL DO PERÍODO AQUI** GROUP BY `centro_custo`") or die(mysql_error());

1 answer

0


Solution.

<li><a>Tabelas Mensais</a><br>
        <form id="form1" name="form1" method="get" action="folhapgt_imprimir.php">
            <select name="data_selecionada" id="data">
                    <?php
                            $dados = mysql_query("SELECT DISTINCT periodo FROM informatica_salario_bruto") or die(mysql_error());
                            if($dados != "")
                            {
                                while ($data = mysql_fetch_array($dados))
                                {
                                      echo "<option value='{$data['periodo']}'"; 
                                      if($_GET['data_selecionada'] == $data['periodo']) echo "selected='selected'";                             
                                            echo ">{$data['periodo']}</option>";
                                }
                            }
                            else 
                            {
                                $dados = mysql_query("SELECT DISTINCT periodo FROM informatica_tributos") or die(mysql_error());

                                while ($data = mysql_fetch_array($dados))
                                {
                                     echo "<option value='{$data['periodo']}'"; 
                                     if($_GET['data_selecionada'] == $data['periodo']) echo "selected='selected'";                              
                                         echo ">{$data['periodo']}</option>";
                                }
                            }
                        ?>          
            </select>       
            <input type="submit" name="submit" id="submit" value="OK" style="margin-left: 10px;">                
 </li>
       </form>

Then on the page where you want to get the value put

$date = $_GET['date selected'];

Browser other questions tagged

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