2
I’m trying to perform the following query in the database, through an html form, only in php I’m only able to fetch all the data from my table. In case the user would choose the type of filter and a query would be made in the database, I’m only using a table in my database.
<form action="busca_filtro.php" method="GET">
Data:
<td align="left">
<input name="tbxDe" type="text" value="13/05/2015" maxlength="10" id="tbxDe" style="height:23px;width:120px;">
até
<input name="tbxAte" type="text" value="14/05/2015" maxlength="10" id="tbxAte" style="height:23px;width:125px;">
</td>
<br><br>
Tipo de Manifestação:
<select name="tipoManifestacao" id="tipoManifestacao" style="">
<option value="-1">Todos</option>
<option value="0">Conservação de barreiras de concreto</option>
<option value="1">Defensas metálicas e cercas</option>
<option value="2">Mato alto ao longo da pista</option>
<option value="3">Pichação ao longo da estrada</option>
<option value="4">Limpeza de canaletas e bueiros</option>
<option value="5">Iluminação de passarelas</option>
<option value="6">Conservação de ponto de ônibus</option>
<option value="7">Conservação de pontes, viadutos e túneis</option>
<option value="8">Conservação de sinalização (placas, faixas)</option>
<option value="9">Buraco no asfalto</option>
<option value="10">Lixo na estrada</option>
<option value="11">Queimada</option>
<option value="12">Remoção de animais mortos da estrada.</option>
</select>
<br><br>
Concessionária:
<select name="concessionaria" id="concessionaria" style="">
<option selected="selected" value="-1">Todas</option>
<option value="Autovias">Autovias</option>
<option value="CART">CART</option>
<option value="CCR Autoban">CCR Autoban</option>
<option value="CCR Rodoanel Oeste">CCR Rodoanel Oeste</option>
<option value="CCR SPVIAS">CCR SPVIAS</option>
<option value="CCR Via Oeste">CCR Via Oeste</option>
<option value="Centrovias">Centrovias</option>
<option value="Colinas">Colinas</option>
<option value="Ecopistas">Ecopistas</option>
<option value="Ecovias">Ecovias</option>
<option value="Intervias">Intervias</option>
<option value="Renovias">Renovias</option>
<option value="Rodovias do Tiete">Rodovias do Tiete</option>
<option value="Rota das Bandeiras">Rota das Bandeiras</option>
<option value="Spmar">Spmar</option>
<option value="Tebe">Tebe</option>
<option value="Triangulo do Sol">Triângulo do Sol</option>
<option value="Via Rondon">Via Rondon</option>
<option value="vianorte">Via Norte</option>
</select>
<br><br>
Status:
<select name="status" id="status" style="">
<option selected="selected" value="-1">Todos</option>
<option value="0">Aguardando</option>
<option value="1">Em Atendimento</option>
<option value="2">Atendido</option>
</select>
<br><br>
Prazo:
<select name="dataAtendimento" id="dataAtendimento" style="">
<option selected="selected" value="-1">Todos</option>
<option value="0">Vencidas</option>
<option value="1">Em Dia</option>
</select>
<br><br>
<input type="reset" value="Remover">
<input type="submit" value="Filtrar">
</form>
</body>
<?php
//Conexão com o BD
include_once("Config.php");
if($tipoManifestacao = isset($_GET['tipoManifestacao"']) ||
$concessionaria = isset($_GET['concessionaria']) ||
$status = isset($_GET['status']) ||
$$dataAtendimento = isset($_GET['dataAtendimento'])){
$sql = "SELECT * FROM tb_manifestacoes";
$result=mysqli_query($db,$sql);
while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){
echo "Tipo Manifestacao :{$row['tipoManifestacao']} <br> ".
"Concessionaria: {$row['concessionaria']} <br> ".
"Status: {$row['status']} <br> ".
"Data Atendimento : {$row['dataAtendimento']} <br> ".
"--------------------------------<br>";
}
}else{
echo "Erro";
}
?>
In this structure would search the data if the user chose one or two or three options, according to what he chose? In the case of data recovery it could be something like this: $result = mysqli_query($db, $sql); $num = mysqli_num_rows($result); while($search = mysqli_fetch_assoc($result){ echo '<pre>'; print_r($search); echo '</pre>'; }
– José Roberto Oliveira