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
| <?php
$result=1;
while ($result <=3) {
$nb_eleves= mt_rand(1, 500);
$nb_sportif= mt_rand(1, $nb_eleves);
$nb_sportifs=$nb_sportif;
$licences="0";
while ($nb_sportif >=0 ){
$nb_sport= mt_rand(1, 3);// choix du nombre de sport
$licences=($nb_sport + $licences);// on donne un nombre de licences par sportif
$nb_sportif --;
}
$dbh = new PDO ('mysql:host=localhost;dbname=devoir-ecole', 'root', '');
$dbh->query("UPDATE ecoles SET nb_eleves='$nb_eleves',nb_sport='$nb_sportifs',licences='$licences' WHERE id='$result'");
$result++;
}
// creation des 5 valeurs dans la base de données sport ( a partir de $distribution)
$id=1;
while ($id <=3) {
$dbh = new PDO ('mysql:host=localhost;dbname=devoir-ecole', 'root', '');
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sth = $dbh->prepare("SELECT licences FROM ecoles WHERE id=$id");
$sth->execute();
$distrib = $sth->fetchAll(PDO::FETCH_ASSOC);
//tableau de tableau
foreach($distrib as $delivery){
$distribution=$delivery['licences'];
$boxe=mt_rand(0, $distribution);
$cyclisme=mt_rand(0, ($distribution - $boxe));
$judo=mt_rand(0, ($distribution - ($cyclisme + $boxe)));
$football=mt_rand(0, ($distribution - ($cyclisme+$boxe+$judo)));
$natation=($distribution - ($cyclisme+$boxe+$judo+$football));
$dbh->query("UPDATE sports SET boxe='$boxe', football='$football', judo='$judo', natation='$natation', cyclisme='$cyclisme' WHERE id='$id'");
$id++;
}
}
?> |
Partager