Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
 
class postManager {
 
    private $_bdd;
 
    public function __construct($bdd) {
 
        $this->setDb($bdd);
    }
 
    public function setDb(PDO $dbh) {
 
        $this->__bdd = $dbh;
    }
 
    public function getSchoolsStudentsNumbers() {
 
        $query = 'SELECT ecole.id, schools_name, SUM(schools_id)
        FROM ecole LEFT JOIN eleves ON ecole.id = eleves.schools_id GROUP BY ecole.id';
 
        $stmnt = $this->__bdd->prepare($query);
 
        $stmnt->execute();
 
        while($row = $stmnt->fetch(PDO::FETCH_ASSOC)) {
 
            $results[] = $row;
        }
 
        return $results;
    }
 
    public function getSchoolsSportStudentsNumbers() {
 
        $query = 'SELECT ecole.id, schools_name, SUM(schools_id) FROM ecole LEFT JOIN eleves ON ecole.id = eleves.schools_id';
 
        $stmnt = $this->__bdd->prepare($query);
 
        $stmnt->execute();
 
        while($row = $stmnt->fetch(PDO::FETCH_ASSOC)) {
 
            $results[] = $row;
        }
 
        return $results;
    }
}
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
 
<?php
 
require('class/postManager.php');
 
try {
 
    $bdd = new PDO('mysql:host=localhost;dbname=ecoles', '10111110', '10111110');
}
 
catch(exception $e) {
 
    die('Erreur ' . $e->getMessage());
}
 
$bdd->exec("SET CHARACTER SET utf8");
 
$manager = new postManager($bdd);
$results = $manager->getSchoolsStudentsNumbers();
var_dump($results);
 
?>
 
<h1>Voici le nombre d'élèves appartenent à telle école</h1>
 
<table>
    <?php if(!empty($results)) : ?>
        <?php foreach($results as $result) : ?>
            <thead>
                <tr>
                    <th>N° Identification</th>
                    <th>Nom de l'école</th>
                    <th>Le nombre d'élèves par école</th>
                </tr>
            </thead>
 
            <tr>
                <td><?php echo $result['id']; ?></td>
                <td><?php echo $result['schools_name']; ?></td>
                <td><?php echo $result['SUM(schools_id)']; ?></td>
            </tr>
        <?php endforeach; ?>
    <?php endif; ?>
</table>
Bonjour, j'aimerais restituer la liste des écoles en affichant pour chacune :
– le nombre d’élèves, (cela est fait). (1)
– le nombre d’élèves pratiquant au moins un sport, (2)
– le nombre d’activités sportives pratiquées, (3)
ça coince au niveau (2 et 3 )