Mysql: Nascondere le pagine dopo una ricerca

lucign0l0

Utente Attivo
9 Ott 2006
50
0
6
ciao a tutti, ho preso da web delle righe per poter impaginare al meglio una select fatta con mysql; adattandolo a quello che avevo già fatto funziona bene.
Quello che non risco a fare è nascondere le pagine quando eseguo una ricerca mirata, ovvero, se dico a php fammi vedere i campi che hanno data "21/04/2021", la prima pagina che mi presenta è quella corretta....ma in più mi fa vedere la numerazione delle pagine successive, che se clicco sono tutto il DB...come posso visualizzare il numero delle pagine riferite alla sola ricerca?

Grazie per l'aiuto.

cn = new mysqli ("$server","$username","$password","$database");

$intervento= $_GET['intervento'];
$data= $_GET['data'];
$fermo= $_GET['fermo'];
$reparto= $_GET['reparto'];
$linea= $_GET['linea'];
$macchina= $_GET['macchina'];

$nRisultatiPerPagina = 100;

$ql= $cn->query("SELECT COUNT(*) as conteggio FROM dati");
$array = $ql-> fetch_assoc();

$totaleRighe = $array['conteggio'];
$totalePagine = ceil($totaleRighe / $nRisultatiPerPagina);



if ( isset($_GET['page'])){
if($_GET['page'] >1){
$start = ($_GET['page']-1) * $nRisultatiPerPagina;
}else{
$start = 0;
}
}else{
$start = 0;
}

$query = $cn->query ("SELECT * FROM dati WHERE (reparto LIKE '%".$reparto."%') AND (fermo LIKE '%".$fermo."%') AND (intervento LIKE '%".$intervento."%') AND (linea LIKE '%".$linea."%') AND (macchina LIKE '%".$macchina."%') AND (data LIKE '%".$data."%') ORDER BY data desc LIMIT ".$start.",".$nRisultatiPerPagina) or die(mysql_error());



?>
<div id="templatemo_header_wrapper">
<div id="templatemo_header">
<div id="templatemo_wrapper">
<p><br/>
</p>
<br/>
</div>
</div>
<p>

</p>
<p>&nbsp;</p>
</div>

<div id="drop-menu">
<div id="templatemo_wrapper">
<ul id="menu">

<li><a href="..\manutenzione" class="current">Home</a></li>
<li><a href="ricerca.html">Ricerca</a></li>
</ul>

</div>
</div>
<div id="templatemo_content_wrapper_dima">
<div class="sidebar_box" >
<p><br />
<br />
</p>
<table width="977" border="0" align="center">
<tbody>


<tr>
<td width="682" align="center" style="font-size: 19px"><p><strong>Registrazioni</strong></p>
<p>&nbsp;</p></td>
</tr>
<tr>
<td align="center"><table width="1091" border="1" align="center" cellspacing="5" margin-right:= "dwcopytype=&quot;CopyTableRow&quot;">
<tbody>
<tr style="height:">
<td width="36" align="center" style="font-family: Constantia, 'Lucida Bright', 'DejaVu Serif', Georgia, 'serif'; color:#FF0000;" span="span">&nbsp;<strong>DATA</strong></span></td>
<td width="86" align="center" style="font-family: Constantia, 'Lucida Bright', 'DejaVu Serif', Georgia, 'serif'; color:#FF0000;" span="span">OPERATORE</td>
<td width="120" align="center" style="font-family: Constantia, 'Lucida Bright', 'DejaVu Serif', Georgia, 'serif'; color:#FF0000;" span="span">INTERVENTO</span></td>
<td width="123" align="center" style="font-family: Constantia, 'Lucida Bright', 'DejaVu Serif', Georgia, 'serif'; color:#FF0000;" span="span">FERMO</span></td>
<td width="123" align="center" style="font-family: Constantia, 'Lucida Bright', 'DejaVu Serif', Georgia, 'serif'; color:#FF0000;" span="span">TURNO</span></td>
<td width="80" align="center" style="font-family: Constantia, 'Lucida Bright', 'DejaVu Serif', Georgia, 'serif'; color:#FF0000;" span="span">REPARTO</span></td>
<td width="114" align="center" style="font-family: Constantia, 'Lucida Bright', 'DejaVu Serif', Georgia, 'serif'; color:#FF0000;" span="span">LINEA</span></td>
<td width="114" align="center" style="font-family: Constantia, 'Lucida Bright', 'DejaVu Serif', Georgia, 'serif'; color:#FF0000;" span="span">MACCHINA</span></td>
<td width="114" align="center" style="font-family: Constantia, 'Lucida Bright', 'DejaVu Serif', Georgia, 'serif'; color:#FF0000;" span="span">ATTIVITA</span></td>
<td width="114" align="center" style="font-family: Constantia, 'Lucida Bright', 'DejaVu Serif', Georgia, 'serif'; color:#FF0000;" span="span">DURATA</span></td>
<td width="114" align="center" style="font-family: Constantia, 'Lucida Bright', 'DejaVu Serif', Georgia, 'serif'; color:#FF0000;" span="span">DESCRIZIONE</span></td>
<td width="114" align="center" style="font-family: Constantia, 'Lucida Bright', 'DejaVu Serif', Georgia, 'serif'; color:#FF0000;" span="span">COMPLETATO</span></td>
<td width="56" align="center" style="font-family: Constantia, 'Lucida Bright', 'DejaVu Serif', Georgia, 'serif'; color:#FF0000;" span="span">MODIFICA</span></td>
<td width="56" align="center" style="font-family: Constantia, 'Lucida Bright', 'DejaVu Serif', Georgia, 'serif'; color:#FF0000;" span="span">ELIMINA</span></td>
</tr>

<?php

while ($riga = mysqli_fetch_array($query)){

$data = $riga['data'];
$operatore = $riga['operatore'];
$intervento = $riga['intervento'];
$fermo= $riga['fermo'];
$turno = $riga['turno'];
$reparto = $riga['reparto'];
$linea = $riga['linea'];
$macchina = $riga['macchina'];
$attivita = $riga['attivita'];
$durata = $riga['durata'];
$descrizione = $riga['descrizione'];
$completato = $riga['completato'];
$id = $riga['id'];

?>


<tr style="height:">
<td align="center" align="center" ><span style="font-family: Constantia, 'Lucida Bright', 'DejaVu Serif', Georgia, 'serif'; font-size: 14px"><strong>&nbsp;&nbsp;<?php echo $data;?>&nbsp;&nbsp;</strong></span></td>
<td align="center" align="center" ><span style="font-family: Constantia, 'Lucida Bright', 'DejaVu Serif', Georgia, 'serif' ; font-size: 14px">&nbsp;&nbsp;<?php echo $operatore;?>&nbsp;&nbsp;</span></td>
<td align="center" align="center" ><span style="font-family: Constantia, 'Lucida Bright', 'DejaVu Serif', Georgia, 'serif'; font-size: 14px">&nbsp;&nbsp;<?php echo $intervento;?>&nbsp;&nbsp;</span></td>
<td align="center" align="center" ><span style="font-family: Constantia, 'Lucida Bright', 'DejaVu Serif', Georgia, 'serif'; font-size: 14px">&nbsp;&nbsp;<?php echo $fermo;?>&nbsp;&nbsp;</span></td>
<td align="center" align="center" > <span style="font-family: Constantia, 'Lucida Bright', 'DejaVu Serif', Georgia, 'serif'; font-size: 14px">&nbsp;&nbsp;<?php echo $turno;?>&nbsp;&nbsp;</span></td>
<td align="center" align="center" ><span style="font-family: Constantia, 'Lucida Bright', 'DejaVu Serif', Georgia, 'serif'; font-size: 14px">&nbsp;&nbsp;<?php echo $reparto;?>&nbsp;&nbsp;</span></td>
<td align="center" align="center" ><span style="font-family: Constantia, 'Lucida Bright', 'DejaVu Serif', Georgia, 'serif'; font-size: 14px">&nbsp;&nbsp;<?php echo $linea;?>&nbsp;&nbsp;</span></td>
<td align="center" align="center" ><span style="font-family: Constantia, 'Lucida Bright', 'DejaVu Serif', Georgia, 'serif'; font-size: 14px">&nbsp;&nbsp;<?php echo $macchina;?>&nbsp;&nbsp;</span></td>
<td align="center" align="center" ><span style="font-family: Constantia, 'Lucida Bright', 'DejaVu Serif', Georgia, 'serif'; font-size: 14px">&nbsp;&nbsp;<?php echo $attivita;?>&nbsp;&nbsp;</span></td>
<td align="center" align="center" ><span style="font-family: Constantia, 'Lucida Bright', 'DejaVu Serif', Georgia, 'serif'; font-size: 14px">&nbsp;&nbsp;<?php echo $durata;?>&nbsp;&nbsp;</span></td>
<td align="center" align="center" ><span style="font-family: Constantia, 'Lucida Bright', 'DejaVu Serif', Georgia, 'serif'; font-size: 14px">&nbsp;&nbsp;<?php echo $descrizione;?>&nbsp;&nbsp;</span></td>
<td align="center" align="center" ><span style="font-family: Constantia, 'Lucida Bright', 'DejaVu Serif', Georgia, 'serif'; font-size: 14px">&nbsp;&nbsp;<?php echo $completato;?>&nbsp;&nbsp;</span></td>
<td align="center"><span style="font-family: Constantia, 'Lucida Bright', 'DejaVu Serif', Georgia, 'serif'; font-size: 14px"><a href="edit_operatore.php?id=<?php echo $id; ?>">Edit</a></span></td>
<td align="left"><span style="font-family: Constantia, 'Lucida Bright', 'DejaVu Serif', Georgia, 'serif'; font-size: 14px"><a href="delete.php?id=<?php echo $id; ?>">Delete</a></span></td>
</tr>

<ul>
<?php
$i++;
}
echo "Page:";
for ($x = 1; $x <= $totalePagine; $x++){
$currentStyle ="";
if ($x==$currentPage)
$currentStyle = "";
else
$currentStyle ="";

echo "<li style=\" ".$currentStyle."margin:5px;border:sold 1px #777;display:inline;padding:5px;\"><a href='./test.php?page=".$x."'>".$x."</a></li>";
}
?>
</ul>
 

Tommy03

Utente Attivo
6 Giu 2018
616
58
28
20
Vicenza
PHP:
$ql= $cn->query("SELECT COUNT(*) as conteggio FROM dati");
Il problema è che il conteggio delle righe è riferito a questa query, che prende dal database tutti i record. Ad esempio se nel db ci sono 2000 righe e 50 che rispettano i filtri, lui mostrerà le 50 righe, però con tutte e 20 le pagine (vuote), perchè nel db conta 2000 righe.
Quindi in pratica devi spostare il conteggio delle righe sotto all'altra query, in modo che conti solo le righe che rispettano i requisiti
 
Discussioni simili
Autore Titolo Forum Risposte Data
K form Inserimento record mysql PHP 2
P Mysql lento a cancellare MySQL 1
P Codifica caratteri speciali mysql php PHP 0
N MAX() + ADD_DATE - per update su Mysql MySQL 0
F Applicazione PHP/MySQL per prenotazioni: limitare il numero massimo di posti prenotabili PHP 20
L tipo boolean non funzionante su mariadb (mysql). E codice php 7.4. PHP 0
M PHP/MySQL - Estrarre valori min e max di ogni gruppo PHP 5
W MySQL ciclo in SELECT MySQL 0
L Mysql gestionale multipiattaforma MySQL 0
W MySQL SELECT list dinamica MySQL 0
M utilizzo mysql in nodejs - crea createdAt e updateAt MySQL 1
T colonne di tabelle mysql ordinate MySQL 0
M Sintassi "personalizzata" per mysql workbench? MySQL 0
A Mysql MySQL 0
F Ricreare struttura php+mysql su Xampp Apache 0
M Array associativi php su 2 campi mysql PHP 10
Z Controllo giorni MYSQL PHP 0
L php mysql non salva solo id PHP 21
L php mysql cerca e visualizza pagina PHP 0
R Aggiornare record mysql con Ajax, jQuery e php Ajax 2
S problema con recupero dati tabella mysql PHP 2
E Progressbar estrazione dati da tabella mySQL Ajax 9
Z MySql injection PHP PHP 1
D controllare valore in tabella mysql PHP 0
A pulsante di update campo mysql con javascript Javascript 2
R Tutto su utf-8 ma ancora problemi con i caratteri speciali in mysql MySQL 1
T differenza fra mysql xampp e un mysql server Database 0
R Importazione csv su mysql tramite array PHP 2
Z Problema con INT MySQL PHP 1
Z Problema database MySQL con XAMPP PHP 0
D problema php mysql PHP 1
D problema php mysql PHP 1
N Server mysql non raggiungibile da connessione esterna MySQL 1
B Crea pdf da tabella mysql "ultima riga modificata" MySQL 4
D evitare di inserirre duplicati in mysql PHP 4
L salvare codice html in mysql PHP 3
L Google chart php mysql PHP 2
S Gestire scelta dropdown con dati da Mysql PHP 2
K cron job mysql PHP 3
elpirata Query per leggere dati da una tabella mysql e mostrarli a video in base a parametri passati tramite GET PHP 5
R Errore UPDATE tabella mysql PHP 1
R Caricamento immagine su cartella remota + mysql PHP 3
D Emoji in mysql Database 0
L Aiuto per programma web php/mySQL PHP 2
S Problema esportazione tabelle Mysql in Excel PHP 0
S Cancellare una riga MYSQL PHP 1
L Ricerca valore mysql e incremento PHP 73
G database mysql contengono informazioni ? MySQL 0
G Testo in mysql format 3 MySQL 0
S Problemi delle funzioni eliminate con PHP e MySQL PHP 4

Discussioni simili