Datatables populate from select dropdown but not functioning correctly

Datatables populate from select dropdown but not functioning correctly

ofb.rielcantalejoofb.rielcantalejo Posts: 11Questions: 5Answers: 1
edited October 2016 in Free community support

I created a Dropdown list to select which database will be placed. the database is working fine and the dropdown list but the Datatables is not functioning.

How will i fix it? thanks in advance!

The main.php

 <?php include("db.php");    ?>
    <title>Circuiti</title>

    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/bs/jq-2.2.3/pdfmake-0.1.18/dt-1.10.12/af-2.1.2/b-1.2.1/b-colvis-1.2.1/b-flash-1.2.1/b-html5-1.2.1/b-print-1.2.1/cr-1.3.2/fc-3.2.2/kt-2.1.2/r-2.1.0/sc-1.4.2/se-1.2.0/datatables.min.css"/>
 <script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
    <script type="text/javascript" src="https://cdn.datatables.net/v/bs/jq-2.2.3/pdfmake-0.1.18/dt-1.10.12/af-2.1.2/b-1.2.1/b-colvis-1.2.1/b-flash-1.2.1/b-html5-1.2.1/b-print-1.2.1/cr-1.3.2/fc-3.2.2/kt-2.1.2/r-2.1.0/sc-1.4.2/se-1.2.0/datatables.min.js"></script>
 
<script type="text/javascript">
$(document).ready(function(){
    $('#country').on('change',function(){
        var countryID = $(this).val();
        if(countryID){
            $.ajax({
                type:'POST',
                url:'ajaxquery.php',
                data:'Cod='+countryID,
                success:function(html){
                    $('#state').html(html);
                    $('#city').html('<option value=""></option>'); 
                }
            }); 
        }else{
            $('#state').html('<option value="">Select Circuito first</option>');
            $('#city').html('<option value="">Select state first</option>'); 
        }
    });    
$('#table').dataTable({   
                 "oSearch": {"bSmart": false},
      dom: '<"coll"B><"search"f><"table"t><"info" i><"list"l><"pag"p>',
    
 buttons: [{  
            extend: 'collection',
            text: 'Esporti',        
      buttons: [ {
                extend: 'excel',
                text: 'Excel',
                exportOptions: {
                    modifier: {
                        selected: true
                                }}},    
            ]}, ],
         select: {
        style: 'multi',
         selector: ' tr>td:nth-child(4), tr>td:nth-child(5), tr>td:nth-child(6), tr>td:nth-child(7)'
    }   });  });
</script>

</head><body>
 <?php
    include('db.php');   
  $query = $con->query("SELECT * FROM circuiti;");
    $rowCount = $query->num_rows;
    ?>
    <select name="country" id="country">
        <option value="">Sceglie Cliente</option>
        <?php
        if($rowCount > 0){
            while($row = $query->fetch_assoc()){ 
                 echo '<option value="'.$row['Cod'].'">'.$row['descrizione'].'</option>';
            }
        }else{
            echo '<option value="">No data</option>';}
        ?>
    </select>
<table  class='table table-striped' id ='table' >
                <thead><tr>
                        <th class = 'col1'></th>
                        <th>Super Esercente</th>
                         <th>Invia SMS</th>
                         <th>Azienda</th>
                 </tr></thead>               
              <tbody style='height:110px' id = 'state'>
              </tbody>
              </table>
</body>

Here is the Ajaxquery.php where the rows are being called.

<?php
include('db.php');
if(isset($_POST["Cod"]) && !empty($_POST["Cod"])){
   $query = $con->query("SELECT * FROM clienti where (utenza =2 OR utenza =5) and Cod =".$_POST['Cod']." ORDER BY es ;"
);
    $rowCount = $query->num_rows;
    if($rowCount > 0){  
   while($row = $query->fetch_assoc()){ 
        
    echo '<td value="'.$row['Cod'].'">' .$row['Utente']. '</td>';
               echo '<td value="'.$row['Cod'].'">' .$row['Utente']. '</td>';
                      echo '<td value="'.$row['Cod'].'">' .$row['Utente']. '</td>';
                        echo '<td value="'.$row['Cod'].'">' .$row['Utente']. '</td>';                     
    } }else{
        echo '<option value="">Nessun Disponibile</option>';
    }} ?>

Answers

This discussion has been closed.