Add another select filter

Add another select filter

nhakk7nhakk7 Posts: 3Questions: 2Answers: 0

I have a table with two select options filters "Marca" and "Modelo", works fine.. But i'm trying to add one more, "Periodo" don't give any error. But when i select a option "Periodo" just dont do nothing. Any idea?

<select id='searchBymarca' class="form-control "> php code... </select>
<select id="searchBy_modelo" class="form-control" required=""> php code... </select>

I add this new line

<select id="searchBy_periodo" class="form-control" required="">
<option value="">Periodo</option>
<?php $periodos = $pdo->query("SELECT DISTINCT periodo FROM tapetes")->fetchAll(PDO::FETCH_ASSOC);
foreach ($periodos as $periodo) {
echo "<option value='{$periodo['periodo']}'>{$periodo['periodo']}</option>";
} ?> </select>

File products.php

$searchBy_modelo = $_POST['searchBy_modelo'];   
$searchBymarca = $_POST['searchBymarca'];

I add this new line

$searchBy_periodo = $_POST['searchBy_periodo'];

$searchQuery = " ";

if($searchBymarca != ''){
    $searchQuery .= " and (marca ='".$searchBymarca."' ) ";
}
if($searchBy_modelo != ''){
    $searchQuery .= " and (modelo='".$searchBy_modelo."') ";
}

I add this new line

if($searchBy_periodo != ''){
    $searchQuery .= " and (periodo='".$searchBy_periodo."') ";              
}

if($searchValue != ''){
$searchQuery .= " and (link like '%".$searchValue."%' or
marca like '%".$searchValue."%' or

I add this new line

periodo like '%".$searchValue."%' or  

ref like '%".$searchValue."%' or
modelo like'%".$searchValue."%' ) ";
}

Script in main page

 $(document).ready(function () {        
        var dataTable = $('#product').DataTable({
            columnDefs: [{ orderable: false, targets: 0 } ],
            "searching": false, 
            'processing': true,            
            // "bPaginate": false, //
            'serverSide': true,
            'serverMethod': 'post',
            "lengthMenu": [[25, 50, 100,500,1000], [25, 50,100,500,1000]],
            'dom': 'rtp',
            'buttons': [], 
            "language": {
                "processing": "<img style='width:300px; height:200px;' src='load.gif' />",
            },
            'ajax': {
                'url': 'products.php',
                'data': function (data) {
                    var searchBymarca = $('#searchBymarca').val();
                    var searchBy_modelo = $('#searchBy_modelo').val();

I add this new line

                var searchBy_periodo = $('#searchBy_periodo').val();   



data.searchBymarca = searchBymarca;
data.searchBy_modelo = searchBy_modelo;

I add this new line

                data.searchBy_periodo = searchBy_periodo;              

}
},

Answers

Sign In or Register to comment.