ORDER BY qui ne fonctionne pas
Posté : 30 nov. 2012, 01:44
Bonjour,
quand j'effectue cette requête, les ORDER ne sont pas pris en comptes, ils sont pas ordonnés comme je le demande (voir pas du tout):
quand j'effectue cette requête, les ORDER ne sont pas pris en comptes, ils sont pas ordonnés comme je le demande (voir pas du tout):
<?php
if(isset($_GET['ordre'])) {
if($_GET['ordre'] == "DESC") {
$ordre = "DESC";
} elseif($_GET['ordre'] == "DESC") {
$ordre = "ASC";
} else {
$ordre = "DESC";
}
} else {
$ordre = "DESC";
}
if(isset($_GET['tri'])) {
if($_GET['tri'] == "id") {
$tri = "id";
} elseif($_GET['tri'] == "nom") {
$tri = "nom";
} elseif($_GET['tri'] == "actif") {
$tri = "actif";
} else {
$tri = "id";
}
} else {
$tri = "id";
}
?>
<table>
<tr>
<td colspan="3" align="center">Trier par:
<a href="page.php?tri=id&ordre=<?php echo $ordre; ?>">ID</a> -
<a href="page.php?tri=nom&ordre=<?php echo $ordre; ?>">Nom</a> -
<a href="page.php?tri=actif&ordre=<?php echo $ordre; ?>">Actif</a>
<br />Trier par ordre:
<a href="page.php?tri=<?php echo $tri; ?>&ordre=ASC">Croissant</a> -
<a href="page.php?tri=<?php echo $tri; ?>&ordre=DESC">Décroissant</a>
</td>
</tr>
<tr>
<th>ID</th>
<th>Nom </th>
<th>Actif</th>
</tr>
<?php
$Verif = mysql_query("SELECT * FROM table ORDER BY ".$tri." ".$ordre."");
if(mysql_num_rows($Verif) == 0) {
?>
<tr>
<td colspan="3" align="center">Aucun enregistréement</td>
</tr>
<?php
} else {
while($Infos = mysql_fetch_assoc($Verif)) {
?>
<tr>
<td><?php echo $Infos['id']; ?></td>
<td><?php echo $Infos['nom']; ?></td>
<td><?php echo $Infos['actif']; ?></td>
</tr>
<?php
}
}
?>
</table>