Enfaite j'aimerais que l'utilisateur puisse choisir lui même le trie et changer à sa guise, j'ai trouvé comme code celui ci mais il me met des erreurs pour les lignes en gras pouvez-vous m'aider svp :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
// Connexion à la base de donnée
$base = mysqli_connect ('localhost', 'root', '')
or die("Impossible de se connecter : " . mysqli_error());
mysqli_select_db ($base,'p&v bike') ;
// Le nom de notre table
$tablename = 'produits';
// Tri sur colonne
$tri_autorises = array('Idpr','Designationpr','Prixpr');
$order_by = in_array(isset($_GET['order']),$tri_autorises) ? $_GET['order'] : 'Idpr';
// Sens du tri
$order_dir = isset($_GET['inverse']) ? 'DESC' : 'ASC';
// Préparation de la requête
$sqli = "
SELECT Designationpr, Prixpr, Idpr
FROM produits
ORDER BY {$order_by} {$order_dir}
";
$result = mysqli_query($sqli);
// 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('Idpr', 'idpr') ?></th>
<th><?php echo sort_link('Designationpr', 'designationpr') ?></th>
<th><?php echo sort_link('Prixpr', 'prixpr') ?></th>
</tr>
<?php while( $row=mysqli_fetch_assoc($result) ) : ?>
<tr>
<td><?php echo $row['Idpr'] ?></td>
<td><?php echo $row['Designationpr'] ?></td>
<td><?php echo $row['Prixpr'] ?></td>
</tr>
<?php endwhile ?>
</table>
Enfaite j'aimerais que l'utilisateur puisse choisir lui même le trie et changer à sa guise, j'ai trouvé comme code celui ci mais il me met des erreurs pour les lignes en gras pouvez-vous m'aider svp :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
// Connexion à la base de donnée
$base = mysqli_connect ('localhost', 'root', '')
or die("Impossible de se connecter : " . mysqli_error());
mysqli_select_db ($base,'p&v bike') ;
// Le nom de notre table
$tablename = 'produits';
// Tri sur colonne
$tri_autorises = array('Idpr','Designationpr','Prixpr');
$order_by = in_array(isset($_GET['order']),$tri_autorises) ? $_GET['order'] : 'Idpr';
// Sens du tri
$order_dir = isset($_GET['inverse']) ? 'DESC' : 'ASC';
// Préparation de la requête
$sqli = "
SELECT Designationpr, Prixpr, Idpr
FROM produits
ORDER BY {$order_by} {$order_dir}
";
[b]$result = mysqli_query($sqli);[/b]
// 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('Idpr', 'idpr') ?></th>
<th><?php echo sort_link('Designationpr', 'designationpr') ?></th>
<th><?php echo sort_link('Prixpr', 'prixpr') ?></th>
</tr>
[b]<?php while( $row=mysqli_fetch_assoc($result) ) : ?>[/b]
<tr>
<td><?php echo $row['Idpr'] ?></td>
<td><?php echo $row['Designationpr'] ?></td>
<td><?php echo $row['Prixpr'] ?></td>
</tr>
<?php endwhile ?>
</table>