I continue with the table of filtered by divs. Well, now I'm doing a SELECT that has two options "PVP with VAT" "PVP without VAT".
In the WILE cycle, all the results come out depending on other selects and taken from a BD. What I need to know is how to do so that when you give the pvp select with VAT you add the VAT to the price of the BD, without updating, change the result in the echo.
This is the row where the echo returns:
<div id="pvp"><p style="color: #f67b48;"><?php echo $res['total']; ?>€</p></div>
This is where I do the different queries for the other selects and then by AJAX I change the content of the entire IVD with an ID.
$orden =$_POST['ordenar'];
$tip =$_POST['tipo'];
$id =$_POST['ID'];
$result = null;
if($_POST['tipo'] == 0){
$results = $mysqli->query("SELECT productos.id, productos.producto, productos.imagen, productos.alias, posibles.idproducto, posibles.tipo, posibles.entrada, posibles.mensualidad, posibles.final, posibles.total FROM productos, posibles WHERE productos.id = posibles.idproducto AND posibles.idproducto = $id ORDER BY posibles.total $orden");
}else{
$results = $mysqli->query("SELECT productos.id, productos.producto, productos.imagen, productos.alias, posibles.idproducto, posibles.tipo, posibles.entrada, posibles.mensualidad, posibles.final, posibles.total FROM productos, posibles WHERE productos.id = posibles.idproducto AND posibles.idproducto = $id AND posibles.tipo = $tip ORDER BY posibles.total $orden");
}
mysqli_set_charset("utf8");
while($res = $results->fetch_array()) {
Here is the result of the while that is then printed in the HTML:
<div class="col-12 planos">
<div class="row planos2">
<div class="col-1"><img src="images/<?php echo $res['imagen']; ?>" alt="" class="img-fluid"></div>
<div class="col-2 plan4 corrijepad">
<h4><?php
if ($res['tipo'] == 1) echo "Alquiler";
if ($res['tipo'] == 2) echo "Comprar";
if ($res['tipo'] == 3) echo "Explotación compartida";
?></h4></p>
<p><?php echo $res['producto']; ?> <span><?php echo $res['alias']; ?></span></p>
</div>
<div class="col-2 plan6 center">
<h4>ENTRADA</h4>
<p><?php echo $res['entrada']; ?>€</p>
</div>
<div class="col-2 plan6 center" style="padding: 0px;">
<h4>CUOTA</h4>
<p><?php echo $res['mensualidad']; ?><span>€/mes (36)</span></p>
</div>
<div class="col-2 plan6 center" style="padding: 0px;">
<h4>FINAL</h4>
<p><?php echo $res['final']; ?>€</p>
</div>
<div class="col-2 plan6 center" style="padding: 0px;">
<h4>TOTAL</h4>
<p style="color: #f67b48;"><?php echo $res['total']; ?>€</p>
</div>
<div class="col-1 pull-right" style="padding: 0px;">
<button type="submit" class="btn btn-primary bonton-quiero ">Comprar</button>
<button type="submit" class="btn btn-primary bonton-quiero2 ">Detalles</button>
</div>
</div>
</div>
<?php } ?>
And finally the AJAX that is on the main page:
<script>
$(function(){
$("#ordenar, #tipo, #ID").on("change", function(e){
var ordenar ="";
var tipo ="";
var id ="";
if ($("#ordenar").val() !=null){
ordenar = $("#ordenar").val();
}
if ($("#tipo").val() !=null){
tipo = $("#tipo").val();
}
if ($("#ID").val() !=null){
ID = $("#ID").val();
}
$.ajax({
url: "filtros.php",
type: "post",
dataType: "html",
data: {
'ordenar': ordenar,
'tipo': tipo,
'ID': ID,
},
beforeSend: function(){
$("#res").html("<div class='ui active inline loader'></div>")
},
success: function (resultado){
$("#res").html(resultado);
}
});
});
});
</script>
Here is the form that manages everything:
<form class="ui form" method="post">
<div class="field">
<select class="ui fluid dropdown" id="tipo" name="tipo">
<?php
$result_1 = $mysqli->query("SELECT * FROM tipos " );
echo "<option value='0'>Todos</option>";
while ($row_1 = $result_1->fetch_array())
{
if ($row_1['id'] ==$_GET['necesito'])
{ echo "<option value='".$row_1['id']."' selected>".$row_1['tipo']."</option>";}
else{
echo "<option value='".$row_1['id']."'>".$row_1['tipo']."</option>";
}
}
?>
</select>
</div></div>
<div class="col-3">
<h4 class="h4stn">ORDENAR POR PRECIO</h4>
<div class="field">
<select class="ui fluid dropdown" id="ordenar" name="ordenar">
<option value="">Elige el orden</option>
<option value="ASC">Más barato primero</option>
<option value="DESC">Más caro primero</option>
</select>
</div>
</div>
<div class="col-3">
<h4 class="h4stn">OPCIONES</h4>
<div class="field">
<select class="ui fluid dropdown" id="pvp" name="pvp">
<option value="">¿Como quieres ver los precios?</option>
<option value="si">PVP con iva</option>
<option value="no">PVP con sin iva</option>
</select>
</div>
</div>
<input type="hidden" name="ID" id="ID" value="<?php echo $res['id']; ?>">
<div class="col-3">
<h4 class="h4stn">MODELOS</h4>
<div class="field">
<select class="ui fluid dropdown" id="productos" name="productos" onchange="javascript:handleSelect(this)">
<option value="">Elige el modelo</option>
<?php
//var_dump($_GET);
$results = $mysqli->query("SELECT * FROM productos WHERE estado = 1");
mysqli_set_charset("utf8");
while($res = $results->fetch_array()) {
?>
<option value="equipos.php?ID=<?php echo $res['id']; ?>"><?php echo $res['producto']; ?> <small><?php echo $res['alias']; ?></small></option>
<?php } ?>
</select>
</div>
</div>
</form>