Boucle de tableau 3 dimensions
Bonjour à tous !
Voilà j'enregistre des informations d'horaire, de jour et de semaine dans une table "horaire"
Ma table horaire contient : id, idfilm, semaine, jour, horaire.
Tout est en int, sauf horaire en text.
Voici comment ça rentre dans la base
Code:
1 2 3 4 5
| for ($a=0; $a<$semaine; $a++){
for ($b=0; $b<7; $b++){
for ($c=0; $c<3; $c++){
mysql_query("INSERT INTO horaire VALUES('', '".$dernier_id."', '".$a."', '".$b."', '".$horaire[$a][$b][$c]."')");
} } } |
Pour le ressortir, c'est simple.
Voici un test :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| <?php
mysql_connect("localhost", "root", "");
mysql_select_db("cinema");
$sql_affiche2='SELECT * FROM horaire WHERE idfilm=6';
$req_affiche2 = mysql_query($sql_affiche2) or die('Erreur SQL !<br />'.$sql_affiche2.'<br />'.mysql_error());
while ($data_affiche2 = mysql_fetch_array($req_affiche2)) {
?>
<tr>
<td>
<?php echo $data_affiche2['horaire']; ?><br />
</td>
</tr>
<?php
}
?> |
ça m'affiche bien les horaires à la ligne.
Mais moi j'voudrais les afficher dans un tableau comme ceci :
Code:
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
| <table width="100%" border="0" cellspacing="0" cellpadding="00">
<tr>
<td>Lundi</td>
<td>14h</td>
</tr>
<tr>
<td>Mardi</td>
<td>17h</td>
<table width="100%" border="0" cellspacing="0" cellpadding="00">
<tr>
<td>Lundi</td>
<td>Mardi</td>
<td>Mercredi</td>
<td>Jeudi</td>
<td>Vendredi</td>
<td>Samedi</td>
<td>Dimanche</td>
</tr>
<tr>
<td>14h</td>
<td>14h</td>
<td>15h</td>
<td>17h - 22h - 00h30</td>
<td>18h</td>
<td>19h</td>
<td>22h - 00h</td>
</tr>
</table> |
J'ai donc pensé à une chose :
- Faire 7 requêtes différentes pour chaque jour grâce à une boucle.
Mais je me dis qu'il y a beaucoup plus simple...
Est-ce que vous pourriez m'aider ?
Merci d'avance :)