Salve a tutti avrei bisogno di una mano per risolvere questo problema.
Io ho questo codice che mi ordina questa tabella, con i vari campi per ordine id DESC.
Codice PHP:
<?php
// connessione al database
include('connect-db.php');
// ottiene i risultati dal database
$result = mysql_query("SELECT * FROM clienti ORDER BY id DESC")
or die(mysql_error());
$total_results = mysql_num_rows($result);
$per_page = 10;
$total_pages = ceil($total_results / $per_page);
if (isset($_GET['page']) && is_numeric($_GET['page']))
{
$show_page = $_GET['page'];
// mi assicuro che il valore di $show_page sia valido
if ($show_page > 0 && $show_page <= $total_pages)
{
$start = ($show_page -1) * $per_page;
$end = $start + $per_page;
}
else
{
// errore - mostra il primo set di risultati
$start = 0;
$end = $per_page;
}
}
else
{
// se la pagina non è impostata, mostra il primo set di risultati
$start = 0;
$end = $per_page;
}
// visualizza i dati in tabella
echo "<table class='table' cellpadding='4'>";
echo "<tr> <th class='client'></th><th>ID</th> <th>Nome</th> <th>Cognome</th> <th>Indirizzo</th> <th>Telefono/Cellulare</th> <th>E-mail</th> <th>Codice Fiscale</th> <th>Partita iva</th> <th>Modifica</th> <th>Elimina</th></tr>";
// loop tra i risultati della query del database, visualizzandoli in tabella
for ($i = $start; $i < $end; $i++)
{
// mi assicuro che PHP non cerchi di mostrare risultati che non esistono
if ($i == $total_results) { break; }
// emissione del contenuto di ogni riga in una tabella
echo "<tr>";
echo '<td class="cli"><img src="img/cliente.jpg"/></a></td>';
echo '<td>' . mysql_result($result, $i, 'id') . '</td>';
echo '<td>' . mysql_result($result, $i, 'ragsoc1') . '</td>';
echo '<td>' . mysql_result($result, $i, 'ragsoc2') . '</td>';
echo '<td>' . mysql_result($result, $i, 'indirizzo') . '</td>';
echo '<td>' . mysql_result($result, $i, 'tel') . '</td>';
echo '<td>' . mysql_result($result, $i, 'mail') . '</td>';
echo '<td>' . mysql_result($result, $i, 'cf') . '</td>';
echo '<td>' . mysql_result($result, $i, 'pi') . '</td>';
echo '<td><a href="edit.php?id=' . mysql_result($result, $i, 'id') . '"><img src="img/edit.png"/></a></td>';
echo '<td><a href="delete.php?id=' . mysql_result($result, $i, 'id') . '"><img src="img/cancella.png"/></a></td>';
echo "</tr>";
}
echo "</table>";
for ($i = 1; $i <= $total_pages; $i++)
{
echo "<div id='page'><a href='view.php?page=$i'>$i.</a></div>";
}
echo '<div id="add-cliente"><a href="new.php"><img src="img/add-cliente.jpg" title="Nuovo cliente" alt="Nuovo cliente"/></a></div>';
echo '<div id="add-pc"><a href="rip.php"><img src="img/add-pc.jpg" title="Nuova riparazione" alt="Nuova riparazione"/></a></div>';
echo '<div id="add-negozio"><a href="negozi.php"><img src="img/add-negozio.jpg" title="Nuovo negozio" alt="Nuovo negozio"/></a></div>';
?>
Vorrei creare dei pulsanti che mi ordinassero la tabella per esempio in ASC o, per campo, valore ecc...Come posso fare? Grazie in anticipo e buone vacanze