1
I’m creating a filter for an online store, which will have these fields:
And so far select * was working, but when I started deploying the filter it stopped working.
Here is the form code and order to print:
<div class="conainer">
<div class="card mx-auto w-100">
<div class="card-header">
<h5 style="color:#007BFF;">Molas de compressão Pesquisa</h5>
</div>
<div class="card-body">
<form action="action.php" method="POST">
Referencia:
<input type="text" placeholder=" Search" name="referencia"style="font-family:Arial, FontAwesome">
<br><br>
<div class="row">
Diametro do Aço (d):
<div class="col-md-4">
<input type="text" name="d1" size="6" placeholder="min">
<input type="text" name="d2" size="6" placeholder="max">
</div>
Comprimento total (L0):
<div class="col-md-4">
<input type="text" name="comp1" size="6" placeholder="min">
<input type="text" name="comp2" size="6" placeholder="max">
</div>
</div>
<br>
<div class="row">
Diametro Exterior (DE):
<div class="col-md-4">
<input type="text" size="6" name="de1" placeholder="min">
<input type="text" name="de2" size="6" placeholder="max">
</div>
Passo (P):
<div class="col-md-4">
<input type="text" name="passo1" size="6" placeholder="min">
<input type="text" name="passo2" size="6" placeholder="max">
</div>
<br>
</div>
<br>
<div class="row">
<div class="form-group">
<label for="exampleFormControlSelect1">Ordenar por:</label>
<select class="form-control" name="ordenar">
<option>Referencia</option>
<option>Diametro do Aço (d)</option>
<option>Comprimento total (L0)</option>
<option>Diametro Exterior (DE)</option>
<option>Passo (P)</option>
</select>
</div>
<div class="col-md-9">
<div align="right">
<img src="imagens/desenho33.png" align="right" height="250" width="350" >
</div>
</div>
</div>
<br>
<div align="right">
<button type="reset" align="right" class="btn btn-primary">Reset</button>
<button type="submit" align="right" class="btn btn-primary">Continuar</button>
</div>
</form>
</div>
</div>
</div>
<br>
<div class="jumbotron">
<div class="container-fluid">
<div class="row">
<div class="col-md-1">Referência</div>
<div class="col-md-2">Diametro do Aço (DE)</div>
<div class="col-md-2">Comprimento Total (L0)</div>
<div class="col-md-2">Diametro Exterior</div>
<div class="col-md-1">Passo</div>
<div class="col-md-1">Preço</div>
<div class="col-md-1"></div>
</div>
</div>
</div>
<div id="get_product"></div>
Here’s the other file you should select and then print on the other page:
<?php
$d1=$_POST["d1"];
$d2=$_POST["d2"];
$comp1=$_POST["comp1"];
$comp2=$_POST["comp2"];
$de1=$_POST["de1"];
$de2=$_POST["de2"];
$passo1=$_POST["passo1"];
$passo2=$_POST["passo2"];
$ordenar=$_POST["ordenar"];
include ("db.php");
if(isset($_POST["getproduct"])){
$ordenar="nome";
}
else{
$ordenar=$_GET["ordenar"];
}
switch($ordenar){
case "referencia":
$ordenar_por="order by referencia";
case "diametroaco":
$ordenar_por="order by diametroaco";
case "comprimentototal":
$ordenar_por="order by comprimentototal";
case "diametroexterior":
$ordenar_por="order by diametroexterior";
case "passo":
$ordenar_por="order by passo";
}
// $molcomp_query="SELECT * FROM stock_comp";
$molcomp_query="select * from stock_comp where diametroaco BETWEEN '".$d1."' and '".$d2."' $ordenar_por";
$run_query = mysqli_query($con,$molcomp_query);
if (mysqli_num_rows($run_query) > 0){
while($row = mysqli_fetch_array($run_query)){
$id_mol_comp=$row['id_mol_comp'];
$referencia=$row['referencia'];
$diametroaco=$row['diametroaco'];
$comprimentototal=$row['comprimentototal'];
$diametroexterior=$row['diametroexterior'];
$passo=$row['passo'];
$preco=$row['preco'];
echo"
<div class='card mx-auto w-100'>
<div class='card-body'>
<div class='row'>
<div class='col-md-1'>$referencia</div>
<div class='col-md-2'>$diametroaco</div>
<div class='col-md-2'>$comprimentototal</div>
<div class='col-md-2'>$diametroexterior</div>
<div class='col-md-1'>$passo</div>
<div class='col-md-1'>$preco</div>
<div class='col-md-1'><i style='font-size:30px' class='fa'></i> <i style='font-size:30px' class='fa'></i> </div>
</div>
</div>
</div>
<br>
";
}
}
?>
And now when I click on the "continue" button of the form, the site exchange page, to http://localhost/fanamol/action.php due to <form action="action.php" method="POST">
. As I can click the continue button, and the action is executed in the action.php file and return the information to the main file, without the main file leaving the screen?
To do what you want, search by Ajax
– Woss
I know what ajax is, but I can’t just make a select with conditions and print on the same page where I already printed select * before?
– edshewa
Yes, with Ajax. Otherwise you will have to leave the page.
– Woss
Just like @Andersoncarloswoss said.
– Wees Smith