1 pièce(s) jointe(s)
mySQL/PHP et algorithmique (comment créer un tableau HTML avec le résultat de la requête)
Salut, et déso si je poste pas au bon endroit ^^
Soit 3 tables : articles, association et tags ; à l'aide d'une requête avec jointure j'obtiens donc une liste de tout ça.
Sauf qu'après en PHP j'arrive pas à faire un tableau conforme : il manque les <td> vides.
Table articles :
ID |
STATUS |
DATE |
TITRE |
CORPS |
1 |
pub |
201706071433 |
titre du billet 1 |
corps du billet 1 |
2 |
dep |
201706091112 |
titre du billet 2 |
corps du billet 2 |
Table associations :
IDART |
IDTAG |
1 |
2 |
1 |
3 |
1 |
4 |
1 |
5 |
1 |
6 |
2 |
4 |
2 |
3 |
Table tags :
ID |
TAG |
1 |
Non classé |
2 |
cuisine |
3 |
loisir |
4 |
maison |
5 |
mode |
6 |
musique |
La requête suivante :
Code:
1 2 3 4 5 6 7
|
select * from articles
inner join associations on
associations.idart = articles.id
inner join tags on
associations.idtag = tags.id
order by id |
Me retourne :
ID |
STATUS |
DATE |
TITRE |
CORPS |
IDART |
IDTAG |
TAG |
... |
|
|
|
|
|
|
|
2 |
dep |
201706091112 |
titre du billet 2 |
corps du billet 2 |
2 |
4 |
maison |
... |
|
|
|
|
|
|
|
Jusque là, tout va bien :D
Maintenant le code PHP suivant :
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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
<table>
<tr>
<th>ID</th>
<th>Status</th>
<th>Date</th>
<th>Titre</th>
<th>Corps</th>
<th>Étiquette 1</th>
<th>Étiquette 2</th>
<th>Étiquette 3</th>
<th>Étiquette 4</th>
<th>Étiquette 5</th>
</tr>
<?php
$myBase = 'sqlite:../mysqlitedatabase/base.sqlite' ;
$myPDO = new PDO($myBase) or die("cannot open the database") ;
$listAll = 'select * from articles
inner join associations on
associations.idart = articles.id
inner join tags on
associations.idtag = tags.id
order by id' ;
$myOldId = '' ;
$myNewId = '' ;
$nTags = 0 ;
foreach ($myPDO->query($listAll) as $row) {
$myNewId = $row[0] ;
if ($myNewId != $myOldId) {
$nTags = 1 ;
print '<tr>' ;
print '<td>'.$row[0].'</td>
<td>'.$row[1].'</td>
<td>'.$row[2].'</td>
<td>'.$row[3].'</td>
<td>'.$row[4].'</td>' ;
print '<td>'.$row[8].'</td>' ;
} else {
$nTags++ ;
print '<td>'.$row[8].'</td>';
}
$myOldId = $myNewId ;
}
print '</tr>' ;
?>
</table> |
...me retourne ce tableau dégueu où il manque les <td> vides :
Pièce jointe 285579
Ma question est donc où dois-je insérer la commande suivante :
Code:
print '<td> </td>';
Mercià vous pour votre aide.