Bom pessoal estou montando uma agenda telefônica e estou tentando ordenar as tabelas pela coluna quando o usuário clica no cabeçalho da coluna. Eu consegui isso usando um script em java desde site http://tablesorter.com/docs/ mas o que acontece é que eu uso o while pra imprimir a tabela puxando os dados do banco e com o while não ordena. Vou postar o código em php pra vocês terem uma ideia. <html>
<head>
<title>Untitled Document</title>
<style type="text/css">
table#tabela
tr:hover {
background-color: #CCCCCC;
}
#atualizar {
background: url(fundo_div_pesquisa.jpg);
background-repeat:repeat-x;
}
table {
text-align: left;
font-size: 12px;
font-family: verdana;
background: #c0c0c0;
}
table thead {
cursor: pointer;
}
tr:hover {
background-color: #CCCCCC;
}
table thead tr,
table tfoot tr {
background: #c0c0c0;
}
table tbody tr {
background: #f0f0f0;
}
td, th {
border: 1px solid white;
}
</style>
</head>
<body>
<?php
include "conexao_banco.php";
?>
<form id="form1" name="form1" method="post" action="">
<table cellspacing="1" cellpadding="2" id="tabela">
<thead>
<tr>
<th scope="col">Sel.</th>
<th scope="col">Nome</th>
<th scope="col">Telefone 01</th>
<th scope="col">Telefone 02</th>
<th scope="col">Telefone 03</th>
<th scope="col">Telefone 04</th>
</tr>
</thead>
<?
// Fazendo uma consulta SQL e retornando os resultados em uma tabela HTML
$query = "SELECT * from contatos";
$sql = mysql_query($query,$conecta);
$row = mysql_num_rows($sql);
while ($row = mysql_fetch_array($sql)) {
$id = $row['id_contato'];
$nome = $row['nome'];
$telefone01 = $row['telefone01'];
$telefone02 = $row['telefone02'];
$telefone03 = $row['telefone03'];
$telefone04 = $row['telefone04'];
?>
<tbody>
<tr>
<td><div align="center"><input type="radio" name="marcado" id="radio" value="<? echo $id;?>" /></div>
<td><? echo $nome; ?></td>
<td><? echo $telefone01; ?></td>
<td><? echo $telefone02; ?></td>
<td><? echo $telefone03; ?></td>
<td><? echo $telefone04; ?></td>
</tr>
</tbody>
<?
}
?>
</table>
<input type="submit" name="button" id="atualizar" value="Atualizar" />
</form>
</body>
</html> Se for necessário mudar como eu gero a tabela pode fala que eu faço de outra maneira. Obrigado.