1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
| <?php
// Connexion à la base de donnée
mysql_connect('localhost','root','');
mysql_select_db('annu_tel');
// Le nom de notre table
$tablename = 'info_personne';
// Tri sur colonne
$tri_autorises = array('nom','prenom','etablissement','login','LibFonction', 'LibService', 'typepersonnel', 'fincontrat');
$order_by = in_array($_GET['order'],$tri_autorises) ? $_GET['order'] : 'nom';
// Sens du tri
$order_dir = isset($_GET['inverse']) ? 'DESC' : 'ASC';
// Préparation de la requête
$sql = "
SELECT *
FROM {$tablename}
ORDER BY {$order_by} {$order_dir}
";
$result = mysql_query($sql);
// Notre fonction qui affiche les liens
function sort_link($text, $order=false)
{
global $order_by, $order_dir;
if(!$order)
$order = $text;
$link = '<a href="?order=' . $order;
if($order_by==$order && $order_dir=='ASC')
$link .= '&inverse=true';
$link .= '"';
if($order_by==$order && $order_dir=='ASC')
$link .= ' class="order_asc"';
elseif($order_by==$order && $order_dir=='DESC')
$link .= ' class="order_desc"';
$link .= '>' . $text . '</a>';
return $link;
}
// Affichage
?>
<style type="text/css">
a.order_asc,
a.order_desc:hover {
padding-right:15px;
background:transparent url(s_asc.png) right no-repeat;
}
a.order_desc,
a.order_asc:hover {
padding-right:15px;
background:transparent url(s_desc.png) right no-repeat;
}
</style>
<table>
<tr>
<th><?php echo sort_link('Nom', 'nom') ?></th>
<th><?php echo sort_link('Prenom', 'prenom') ?></th>
<th><?php echo sort_link('Site', 'etablissement') ?></th>
<th><?php echo sort_link('Login', 'login') ?></th>
<th><?php echo sort_link('Fonction', 'LibFonction') ?></th>
<th><?php echo sort_link('Service', 'LibService') ?></th>
<th><?php echo sort_link('Type personnel', 'typepersonnel') ?></th>
<th><?php echo sort_link('Date de fin de contrat', 'fincontrat') ?></th>
</tr>
<?php while( $row=mysql_fetch_assoc($result) ) : ?>
<tr>
<td><?php echo $row['nom'] ?></td>
<td><?php echo $row['prenom'] ?></td>
<td><?php echo $row['etablissement'] ?></td>
<td><?php echo $row['login'] ?></td>
<td><?php echo $row['LibFonction'] ?></td>
<td><?php echo $row['LibService'] ?></td>
<td><?php echo $row['typepersonnel'] ?></td>
<td><?php echo $row['fincontrat'] ?></td>
</tr>
<?php endwhile ?>
</table> |
Partager