Bonsoir,
Je souhaite récupérer mes infos et ensuite créer un tableau, mais je galère un peu et j'ai l'impression que je me complique la vie, pouvez vous me dire comment vous feriez ?
Je dispose des tables (qui sont Type, Article, Caracteristique, Article_carac)
type: (id, nom, description)
article: (id, id_type, marque, modele, description, qutt)
caracteristique: (id, id_type, nom)
article_carac: : (id, id_art, id_carac, valeur)
Je recupère mes infos avec cette requete:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| SELECT
type.nom type_nom, type.description type_description,
article.marque article_marque, article.modele article_modele, article.qutt article_qutt,
article.description article_description, article.id article_id,
caracteristique.nom carac_nom,
article_carac.id art_car_id, article_carac.valeur art_carac_val
FROM type
LEFT JOIN article
ON type.id = article.id_type
LEFT JOIN caracteristique
ON caracteristique.id_type = type.id
LEFT JOIN article_carac
ON article_carac.id_art = article.id
AND article_carac.id_carac = caracteristique.id
WHERE type.id = :id
ORDER BY article.marque DESC |
ce qui me donne:
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 80 81 82 83 84 85 86 87 88 89
| array (size=4)
0 =>
array (size=20)
'type_nom' => string 'type nom Zone de texte' (length=22)
0 => string 'type nom Zone de texte' (length=22)
'type_description' => string 'type description Zone de texte' (length=30)
1 => string 'type description Zone de texte' (length=30)
'article_marque' => string 'article marque zone de texte' (length=28)
2 => string 'article marque zone de texte' (length=28)
'article_modele' => string 'article modele zone de texte' (length=28)
3 => string 'article modele zone de texte' (length=28)
'article_qutt' => string '10' (length=2)
4 => string '10' (length=2)
'article_description' => string 'article description zone de texte' (length=33)
5 => string 'article description zone de texte' (length=33)
'article_id' => string '3' (length=1)
6 => string '3' (length=1)
'carac_nom' => string 'bois' (length=4)
7 => string 'bois' (length=4)
'art_car_id' => string '1' (length=1)
8 => string '1' (length=1)
'art_carac_val' => string '-' (length=1)
9 => string '-' (length=1)
1 =>
array (size=20)
'type_nom' => string 'type nom Zone de texte' (length=22)
0 => string 'type nom Zone de texte' (length=22)
'type_description' => string 'type description Zone de texte' (length=30)
1 => string 'type description Zone de texte' (length=30)
'article_marque' => string 'article marque zone de texte' (length=28)
2 => string 'article marque zone de texte' (length=28)
'article_modele' => string 'article modele zone de texte' (length=28)
3 => string 'article modele zone de texte' (length=28)
'article_qutt' => string '10' (length=2)
4 => string '10' (length=2)
'article_description' => string 'article description zone de texte' (length=33)
5 => string 'article description zone de texte' (length=33)
'article_id' => string '3' (length=1)
6 => string '3' (length=1)
'carac_nom' => string 'beton' (length=5)
7 => string 'beton' (length=5)
'art_car_id' => string '2' (length=1)
8 => string '2' (length=1)
'art_carac_val' => string '10' (length=2)
9 => string '10' (length=2)
2 =>
array (size=20)
'type_nom' => string 'type nom Zone de texte' (length=22)
0 => string 'type nom Zone de texte' (length=22)
'type_description' => string 'type description Zone de texte' (length=30)
1 => string 'type description Zone de texte' (length=30)
'article_marque' => string '-lepetit' (length=8)
2 => string '-lepetit' (length=8)
'article_modele' => string '-' (length=1)
3 => string '-' (length=1)
'article_qutt' => string '0' (length=1)
4 => string '0' (length=1)
'article_description' => string '' (length=0)
5 => string '' (length=0)
'article_id' => string '5' (length=1)
6 => string '5' (length=1)
'carac_nom' => string 'bois' (length=4)
7 => string 'bois' (length=4)
'art_car_id' => null
8 => null
'art_carac_val' => null
9 => null
3 =>
array (size=20)
'type_nom' => string 'type nom Zone de texte' (length=22)
0 => string 'type nom Zone de texte' (length=22)
'type_description' => string 'type description Zone de texte' (length=30)
1 => string 'type description Zone de texte' (length=30)
'article_marque' => string '-lepetit' (length=8)
2 => string '-lepetit' (length=8)
'article_modele' => string '-' (length=1)
3 => string '-' (length=1)
'article_qutt' => string '0' (length=1)
4 => string '0' (length=1)
'article_description' => string '' (length=0)
5 => string '' (length=0)
'article_id' => string '5' (length=1)
6 => string '5' (length=1)
'carac_nom' => string 'beton' (length=5)
7 => string 'beton' (length=5)
'art_car_id' => null
8 => null
'art_carac_val' => null
9 => null |
et je souhaite créer un tableau pour arriver à :
mais pour le moment je n'arrive qu'à:
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
| <table BORDER=1px CELLSPACING=2 CELLPADDING=1>
<tr>
<th>marque</th>
<th>modèle</th>
<?php
while($donnees = $req->fetch())
{
?><th><?php echo $donnees['carac_nom'];?></th>
<?php $tableau[] = $donnees;
}
?>
</tr>
<?php
foreach($tableau as $cle)
{
if($cle['article_id']!=$article_id_actuelle)
{
$article_id_actuelle=$cle['article_id'];
?>
<tr>
<?php
echo '<td>'.$cle['article_marque'].'</td>';
echo '<td>'.$cle['article_modele'].'</td>';
}
echo '<td>'.$cle['art_carac_val'].'</td>';
}
?>
</table> |
et je ne sais pas trop qu'elle chemin prendre pour réussir.
merci d'avoir lus et de prendre le temps de m'aider.
Partager