-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
79 lines (73 loc) · 2.24 KB
/
index.php
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<title>Simplon exemples sql</title>
</head>
<body style="text-align:center">
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
define('NOM_DB', 'ZOO');
define('UTILISATEUR_DB', 'XXXX');
define('MDP_DB', 'XXXX');
$dbconnexion = new PDO('mysql:host=localhost;dbname='.NOM_DB, UTILISATEUR_DB, MDP_DB, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING));
?>
<h1>Tous les Animaux</h1>
<?php
$Repas = $dbconnexion->query("
SELECT a.nom, a.dateNaissance,
GROUP_CONCAT(r.heureRepas SEPARATOR ' <br/> ') heuresRepas,
GROUP_CONCAT(m.poids SEPARATOR ' + ') poids,
GROUP_CONCAT(al.nomAliments SEPARATOR ' <br/> ') nomsAliments,
GROUP_CONCAT(f.nomFournisseurs SEPARATOR ' <br/> ') nomsFournisseurs
FROM repas r, animaux a, menus m, aliments al, fournisseurs f
WHERE a.id_animaux=r.id_animaux
AND r.id_repas=m.id_repas
AND m.id_aliments=al.id_aliments
AND al.id_fournisseurs=f.id_fournisseurs
GROUP BY a.nom, a.dateNaissance
");
foreach ($Repas as $Rp) {
$nom = mb_strtoupper($Rp['nom']);
$nomsFour = $Rp['nomsFournisseurs'];
$nomsAlim = $Rp['nomsAliments'];
$heuresRep = $Rp['heuresRepas'];
$poids = $Rp['poids'];
$heureUnique = explode (" <br/> ", $heuresRep);
$fourUnique = explode(" <br/> ", $nomsFour);
$alimUnique = explode(" <br/> ", $nomsAlim);
$poidsUnique = explode(" + ", $poids);
$pdsTxt = '';
$cmTxt = '';
if ($heureUnique[0] == next($heureUnique)) {
$heuresRep = $heureUnique[0];
}
if ($fourUnique[0] == next($fourUnique)) {
$nomsFour = $fourUnique[0];
}
if ($alimUnique[0] == next($alimUnique)) {
$nomsAlim = $alimUnique[0];
/* $i=0;
foreach ($poidsUnique as $pU){
$i += $pU;
}
$poids = $i;
*/
$poids = $poidsUnique[0];
$pdsTxt = "<i>$poids Kg de $nomsAlim</i><br/><b>".$heuresRep." </b>";
}
elseif ($alimUnique[0] != next($alimUnique)){
$i = 0;
foreach ($alimUnique as $aU) {
$pdsTxt .= "<b>".$heureUnique[$i]." <br/></b><i>".$poidsUnique[$i]." Kg de " .$aU."</i><br/>";
$i++;
}
}
echo '<strong>'.$nom.'</strong><br/>'.$Rp['dateNaissance'].'<br/><br/><u> Alimentation:</u><br/>'.$pdsTxt.'<br/><u>Fournisseur:</u><br/><i>'.$nomsFour.'</i><hr>';
};
?>
<h1>Ce qu'ils mangent</h1>
SOON
</body>
</html>