limit show datatable ajax

#Fede5

Nuovo Utente
23 Ott 2019
11
0
1
Ciao ragazzi, ho un problema con la visualizzazione del numero di righe della tabella. La tabella viene visualizzata sempre tutta anche se chiedo di mostrarla a 10 righe per volta. Vi allego il mio codice, magari qualcuno riesce ad aiutarmi...grazie

HTML:
<!DOCTYPE html>
<html>
 <head>
  <title>Progetto</title>
 
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
  <script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
  <script src="https://cdn.datatables.net/1.10.12/js/dataTables.bootstrap.min.js"></script> 
  <link rel="stylesheet" href="https://cdn.datatables.net/1.10.12/css/dataTables.bootstrap.min.css" />
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

 </style>
 </head>
 <body>

<table id="user_data" class="table table-bordered table-striped">
     <thead>
      <tr>
    
       <th width="35%">Cognome</th>
       <th width="35%">Nome</th>
       <th width="10%">Conferma</th>   
       <th width="10%">Adulti</th>     
       <th width="10%">Bambini</th>
       <th width="10%">Modifica</th>
       <th width="10%">Cancella</th>
      </tr>
     </thead>
    </table>
  
  
 </body>
</html>


<script type="text/javascript" language="javascript" >
$(document).ready(function(){       
 
 
 var dataTable = $('#user_data').DataTable({
  "processing":true,
  "serverSide":true, 
  "order":[],
  "lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "Tutti"]],     
  "ajax":{
   url:"fetch.php",
   type:"POST"
  },
  "columnDefs":[
   {
    "targets":[0,1,2, 3, 4, 5, 6],
    "orderable":false,
   },
  ],
        
 });


e fetch.php

PHP:
<?php
include('db.php');
include('function.php');
$query = '';
$output = array();
$query .= "SELECT * FROM prenotazione ";
if(isset($_POST["search"]["value"]))
{
 $query .= 'WHERE Cognome LIKE "%'.$_POST["search"]["value"].'%" ';
 $query .= 'OR Nome LIKE "%'.$_POST["search"]["value"].'%" ';
}
if(isset($_POST["order"]))
{
 $query .= 'ORDER BY '.$_POST['order']['0']['column'].' '.$_POST['order']['0']['dir'].'' ;
  
}
else
{
 $query .= 'ORDER BY Cognome ASC, Nome ASC';
}


if($_POST["length"] != -1){
 
$query .= 'LIMIT' .$_POST['start'] . ',' .$_POST['length'];

}

$statement = $connection->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
$data = array();
$filtered_rows = $statement->rowCount();
foreach($result as $row)
{
 
 $sub_array = array();
 
 $sub_array[] = $row["Cognome"];
 $sub_array[] = $row["Nome"];
 $sub_array[] = $row["Conferma"];
 $sub_array[] = $row["Adulti"];   
 $sub_array[] = $row["Bambini"];     
 $sub_array[] = '<button type="button" name="update" id="'.$row["id"].'" class="btn btn-warning btn-xs update">Modifica</button>';
 $sub_array[] = '<button type="button" name="delete" id="'.$row["id"].'" class="btn btn-danger btn-xs delete">Cancella</button>';
 $data[] = $sub_array;

}
$output = array(
 "draw"    => intval($_POST["draw"]),
 "recordsTotal"  =>  $filtered_rows,
 "recordsFiltered" => get_total_all_records(),
 "data"    => $data
);
echo json_encode($output);
?>


se dal PHP tolgo la linea di codice
PHP:
if($_POST["length"] != -1){

$query .= 'LIMIT' .$_POST['start'] . ',' .$_POST['length'];

}

visualizza la tabella completa e il tasto Show 10/25/50/Tutti non ha nessun effetto mentre se la tengo nel codice non mi viene visualizzata neanche la tabella. Suggerimenti?
 
Discussioni simili
Autore Titolo Forum Risposte Data
Tommy03 Time Limit Exceeded in c++ C/C++ 0
M Limit DATE PHP 6
radioButton Clausola LIMIT non standard in Sql Database 0
L Problema include ed errore server rate limit.... PHP 0
L visualizzare solo 10 record con LIMIT PHP 5
L Rate Limit Exceeded. cosa è ? PHP 4
Monital Valori doppi nel LIMIT PHP 4
D Limit Size con Baol Classic ASP 0
A paginazione problema LIMIT PHP 2
A Select Limit PHP 3
R Concorso Logo Team Vertical Limit Webdesign e Grafica 4
grottafelix Response Buffer Limit Exceeded Classic ASP 13
M Neuer Server einfach Spitze ohne Limit, Web Server 1
grottafelix Bandwidth Limit Exceeded? Discussioni Varie 1
Z Slide show CSS HTML e CSS 1
B jQuery - hide & show li items jQuery 13
Daniele450 [Javascript] Slide show in java script, senza array con nome visibile dell'immagine Javascript 2
filomeni Show Box Supporto Mr.Webmaster 5
G Funzione hide/show button Javascript 5
D [EXCEL] UserForm.Show Error 438 Windows e Software 1
F show() jQuery 1
M Show Hide non funziona su IE jQuery 2
L colums show/hide Javascript 2
S Slide Show Automatico Discussioni Varie 1
S Slide show risultati in php PHP 3
M On clik show div Javascript 0
J Fading Slide Show Javascript 0
J Vite Spiate il reality show interattivo gratuito on line dal 14 ottobre 2009 Presenta il tuo Sito 0
D All the SHOW Presenta il tuo Sito 0
D Visualiazzare Show reel ( da DvD ) in una pagina web Webdesign e Grafica 2
A Form.close & form.show. POCKET PC Programmazione 0
W colori per lo slide show Webdesign e Grafica 12
H creare delle slide-show dai DivX Windows e Software 0
dragoonslair tutorial show directory PHP 5
B Slide show in DHTML Javascript 3
V [Javascript] exportOptions in datatable Javascript 0
F Jquery Ajax Datatable jQuery 1
D Errore su funzione DataTable jQuery 3
Z [VB.net 2013 - MySQL] DataTable: Problemi di caricamento per alcuni dati .NET Framework 1
P problemi con datatable creazione metodo convertTable() ASP.NET 0

Discussioni simili