je 'débute' en php. Je suis en train de créer un site internet mais je rencontre actuellement un petit problème.
Je voudrais en fait creer un tableau ou l'utilisateur pourra le trier en cliquant que l'en tête d'une colonne. (changer le order by en fait)
voici mon code
Code : Tout sélectionner
$pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
$bdd = new PDO('mysql:host=localhost;dbname=stats', 'root', '', $pdo_options);
// Tri sur colonne
$tri_autorises = array('ID','Noms','Nation','Arrivee','Depart');
$order_by = in_array($_GET['order'],$tri_autorises) ? $_GET['order'] : 'ID';
// Sens du tri
$order_dir = isset($_GET['inverse']) ? 'DESC' : 'ASC';
//récupère le contenu
$result = $bdd->query('SELECT * FROM entraineurs ORDER BY '.$order_by.' '.$order_dir);
// 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
?>
<table>
<tr>
<th><?php echo sort_link('ID', 'ID') ?></th>
<th><?php echo sort_link('Noms', 'Noms') ?></th>
<th><?php echo sort_link('Nation', 'Nation') ?></th>
<th><?php echo sort_link('Arrivee', 'Arrivee') ?></th>
<th><?php echo sort_link('Depart', 'Depart') ?></th>
</tr>
<?php while( $row=fetch_assoc($result) ) //[b]le probleme viendrait de cette ligne[/b]
?>
<tr>
<td><?php echo $row['ID'] ?></td>
<td><?php echo $row['Noms'] ?></td>
<td><?php echo $row['Nation'] ?></td>
<td><?php echo $row['Arrivee'] ?></td>
<td><?php echo $row['Depart'] ?></td>
</tr>
<?php endwhile ?>
</table>
( ! ) Fatal error: Call to undefined function fetch_assoc() in C:\wamp\www\stats\test.php on line 80
Call Stack
# Time Memory Function Location
1 0.0009 383616 {main}( ) ..\entest.php:0
je pense que je n'utilise pas correctement la fonction fetch_assoc mais je n'en suis pas sûre et je ne trouve pas de solution.
j’espère qu'un oeil plus expérimenté que le mien trouvera mes erreurs, peut être qu'elle sont grossières mais j'apprend.
merci par avance de votre aide.
cordialement
bst