
le 30/11/2004 à 09:21
header ne marche pas
En voila une bonne idée :)
Perso, je fais pareil, mais j'utilise une constante.
Perso, je fais pareil, mais j'utilise une constante.
CREATE TABLE notes (
id int(11) NOT NULL auto_increment,
id_participant int(11) NOT NULL default '0',
note int(11) NOT NULL default '0',
UNIQUE KEY id (id)
) TYPE=MyISAM;
INSERT INTO notes VALUES (1, 1, 15);
INSERT INTO notes VALUES (2, 1, 12);
INSERT INTO notes VALUES (3, 2, 17);
INSERT INTO notes VALUES (4, 2, 13);
CREATE TABLE participant (
id int(11) NOT NULL auto_increment,
nom text NOT NULL,
UNIQUE KEY id (id)
) TYPE=MyISAM;
INSERT INTO participant VALUES (1, 'LA GLOBULE');
INSERT INTO participant VALUES (2, 'toto');
<html>
<head>
<title>test</title>
</head>
<body>
<?php
$db = mysql_connect('***', '***', '***');
mysql_select_db('***', $db);
$sql = 'SELECT AVG(notes.note) AS moyenne, participant.nom AS eleve FROM notes, participant WHERE participant.id=notes.id_participant GROUP BY participant.id ORDER BY moyenne ASC';
$req = mysql_query($sql) or die('Erreur SQL !'.$sql.''.mysql_error());
while ($data = mysql_fetch_array($req)) {
print_r ($data);
}
?>
</body>
</html>
Array
(
[0] => 13.5000
[moyenne] => 13.5000
[1] => LA GLOBULE
[eleve] => LA GLOBULE
)
Array
(
[0] => 15.0000
[moyenne] => 15.0000
[1] => toto
[eleve] => toto
)