Scarichi lo script da qui: http://tablesorter.com/docs/#Download
Nella pagina dove stampi i risultati presi dal db inserisci nell'head:
codice:
<link rel="stylesheet" href="../themes/blue/style.css" type="text/css" id="" media="print, projection, screen" />
<script type="text/javascript" src="../jquery-latest.js"></script>
<script type="text/javascript" src="../jquery.tablesorter.js"></script>
<script type="text/javascript">
$(function() {
$("table").tablesorter({debug: true});
});
</script>
Dopo dovresti solo sostituire qualcosa nel codice php che hai già fatto tu o hai preso da qualche parte.
Ti faccio una cosa veloce poi la sistemi tu:
Codice PHP:
echo "<table id='rowspan' cellspacing='0' class='tablesorter'>";
echo "<thead><tr>";
echo "<th>[i]ID<i/></th>";
echo "<th>[i]Nome<i/></th>";
echo "<th></th>";
echo "<th ></th>";
echo "</tr></thead>";
define('DB_NAME', 'forms1');
define('DB_USER', 'root');
define('DB_PASSWORD', '');
define('DB_HOST', 'localhost');
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db(DB_NAME, $link);
if (!$db_selected) {
die('Can't use ' . DB_NAME . ': ' . mysql_error());
}
$Nome = str_replace(' ', '%', $_POST['Nome']);
$Numero = str_replace(' ', '%', $_POST['Numero']);
$city = str_replace(' ', '%', $_POST['city']);
$arNome = str_split($Nome);
$arNumero = str_split($Numero);
$arcity = str_split($city);
$Nome='';
foreach ($arNome as $value)
{
if ($value=='%') continue;
$Nome.=$value.'%';
}
$Numero='';
foreach ($arNumero as $value)
{
if ($value=='%') continue;
$Numero.=$value.'%';
}
$city='';
foreach ($arcity as $value)
{
if ($value=='%') continue;
$city.=$value.'%';
}
$sql = mysql_query("SELECT * FROM demo WHERE Autore LIKE '%$Nome%' AND Titolo LIKE '%$Numero%' AND cit LIKE '%$city%' ORDER BY Autore") or die(mysql_error());
while($row=mysql_fetch_array($sql)){
echo "<tbody><tr>";
echo "<td width='auto' bgcolor=”#FF0000 ″>" . "". "[b]" . $row[0] . "". "<b/>". "</td>";
echo "<td width='auto'>" . "" . $row[1] . "" . "</td>";
echo "<td width='auto'>". "</td>";
echo "<td width='auto'>" . "". "[i]" . $row[2] . "<i/>". "" . "</td>";
echo "<td width='auto'>" . "". "[i]" . $row[3] . "<i/>". "" . "</td>";
echo "</tr></tbody></table>";
}
mysql_close();
Credo sia giusto ma tu controlla, se hai problemi chiedi.