Good, I have a catalog of products that I did with a while to show all the products that I have in the db, the thing is that the template I use brings some that I would like to use to filter the products, the thing is. Searching I did something that half worked, but when you press any of the two options in the option, only the one that has class=1
remains.
What I did was with the same data from the while put:
<div class="<?php echo $r["moneda"], ?>">
Then in the select if I choose the option Dollars has a value = 1 so if the field 'currency' of that product is 1 should be and those that are 2 disappear. The thing is that whether I choose the option of value = 1 or the value = 2 always appears to anything. I do not know what can be done that I leave my code
Show products
<?php
while ($r = $query->fetch_array()) { ?>
<div id="productos">
<div class="<?php echo $r["moneda"]; ?>">
<div class="inventory margin-bottom-20 clearfix scroll_effect fadeIn">
<input type="checkbox" name="a" class="checkbox compare_vehicle input-checkbox" id="vehicle_1"/>
<label for="vehicle_1"></label>
<a class="inventory" href="inventory-listing.html">
<div class="title"><?php echo $r["nombre"]; ?></div>
<img src="../images/productos/<?php echo $r["img"]; ?>" class="preview" alt="preview">
<table class="options-primary">
<tr>
<td class="option primary">Body Style:</td>
<td class="spec">Sport Utility Vehicle</td>
</tr>
<tr>
<td class="option primary">Drivetrain:</td>
<td class="spec">4WD</td>
</tr>
<tr>
<td class="option primary">Engine:</td>
<td class="spec">4.8L V8</td>
</tr>
<tr>
<td class="option primary">Transmission:</td>
<td class="spec">8-Speed Tiptronic</td>
</tr>
<tr>
<td class="option primary">Mileage:</td>
<td class="spec">19,585</td>
</tr>
</table>
<table class="options-secondary">
<tr>
<td class="option secondary">Exterior Color:</td>
<td class="spec">Dark Blue Metallic</td>
</tr>
<tr>
<td class="option secondary">Interior Color:</td>
<td class="spec">Black / Titanium Blue</td>
</tr>
<tr>
<td class="option secondary">MPG:</td>
<td class="spec">15 city / 21 hwy</td>
</tr>
<tr>
<td class="option secondary">Stock Number:</td>
<td class="spec">590497</td>
</tr>
<tr>
<td class="option secondary">VIN Number:</td>
<td class="spec">WP1AD29P09LA65818</td>
</tr>
</table>
<img src="http://demo.themesuite.com/automotive/images/carfax.png" alt="carfax" class="carfax"/>
<div class="price"><b>Precio:</b><br>
<div class="figure"><?php if ($r["moneda"] == 1) {
echo "$ " . $r["precio"];
} elseif ($r["moneda"] == 2) {
echo "Cr " . $r["precio"];
} ?><br>
</div>
</div>
<div class="view-details gradient_button"><i class='fa fa-plus-circle'></i> Ver Detalles</div>
<div class="clearfix"></div>
</a>
<div class="view-video gradient_button" data-youtube-id="3oh7PBc33dk"><i class="fa fa-video-camera"></i>
Ver Video
</div>
</div>
</div>
</div>
<?php } ?>
And this is the jQuery you use:
(function(){
var $tabla = $('#productos');
$('#filtro_moneda').change(function(){
var value = $(this).val();
if (value){
$('div.' + value, $tabla).show();
$('div:not(.' + value + ')', $tabla).hide();
}
else{
// Se ha seleccionado All
$('div', $tabla).show();
}
});
})
And here is the option:
<select name="price" class="css-dropdowns" tabindex="1" id="filtro_moneda">
<option value="">Metodo de Pago</option>
<option value="1">Dolares</option>
<option value="2">Créditos</option>
</select>