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
| <?php
if (isset($_POST['choixCat']))
{
$sql = <<<sql
SELECT
designation,
type,
dispo,
description
FROM
materiel
WHERE
`designation` = '{$db->real_escape_string($_POST['choixCat'])}'
sql;
$qry = $db->query($sql) or die ('There was an error [' . $db->error . ']');
$nb_rows = mysqli_num_rows($qry);
$details = '';
$types = []; // [type => [dispo, indispo]]
while ($row = mysqli_fetch_assoc($qry))
{
if ( ! isset($types[$row['type']]))
{
$types[$row['type']] = ['dispo' => 0, 'indispo' => 0];
}
$k = ($row['dispo'] == 0) ? 'indispo' : 'dispo';
++$types[$row['type']][$k]; // on incrémente le bon compteur
}
// fonction d'échappement à l'affichage
$hsc = function($p) { return htmlspecialchars($p, ENT_QUOTES, 'utf-8'); };
?>
yes
<center><h2>SITUATION GLOBALE DU :<?= $hsc($_POST['choixCat']) ?></h2></center>
<?php
if($nb_rows)
{
?>
<center><table bgcolor="#FFFFFF" width="1050" border="0" align="center" cellpadding="0" cellspacing="0">
<thead style="height:1 cm;">
<tr>
<th bgcolor="#669999"><b><u>Désignation</u></b></th>
<th bgcolor="#669999" style="width:6 cm;"><b><u>Caractéristiques techniques</u></b></th>
<th bgcolor="#669999"><b><u>Dotation</u></b></th>
<th bgcolor="#669999"><b><u>Disponible</u></b></th>
<th bgcolor="#669999"><b><u>Indisponible</u></b></th>
</tr>
</thead>
<tbody>
<?php
while ($row = mysqli_fetch_assoc($qry))
{
?>
<tr>
<td><?= $hsc($row['designation']) ?></td>
<td><?= $hsc($row['type'])?></td>
<td bgcolor="#CCCCCC">><?= ($types[$row['type']]['dispo'] + $types[$row['type']]['indispo']) ?></td>
<td bgcolor="#CCCCCC">><?= $types[$row['type']]['dispo'] ?></td>
<td bgcolor="#CCCCCC">><?= $types[$row['type']]['indispo'] ?></td>
</tr>
<?php } ?>
</tbody>
</table></center>
<?php }
}
?> |
Partager