Utiliser les jointures en php/sql
RichieZz
Messages postés
18
Statut
Membre
-
RichieZz Messages postés 18 Statut Membre -
RichieZz Messages postés 18 Statut Membre -
Bonjour,
J'ai créé via php myadmin 2 tables j'ai affiché à l'aide du code suivant les données de la table 1:
if ($formations) {
?>
<table align="center" border="1">
<?php
foreach ($formations as $formation) {
?>
<thead>
<tr>
<th>form_id</th>
<th>form_titre</th>
<th>form_nb_jour</th>
<th>form_reference</th>
<th>form_prix</th>
<th>form_objectifs</th>
<th>form_participants</th>
<th>form_prerequis</th>
<th>items</th>
</tr>
</thead>
<tbody>
<tr>
<td><?=$formation->form_id?></td>
<td><?=$formation->form_titre?></td>
<td><?=$formation->form_nb_jour?></td>
<td><?=$formation->form_reference?></td>
<td><?=$formation->form_prix?></td>
<td><?=$formation->form_objectifs?></td>
<td><?=$formation->form_participants?></td>
<td><?=$formation->form_prerequis?></td>
<td><?=$item->item_titre?></td>
</tr>
</tbody>
<?php
}
}
else {
echo "<tr><td colspan='7'>Aucun résultat</td></tr>";
}
?>
j'aimerai à présent rajouter une colonne de ma deuxième table a ce tableau, j'ai déjà créé une fonction qui contient la requête sql de la jointure et j'aimerai afficher le résultat de cette requête dans la nouvelle colonne de mon tableau et je ne trouve pas de solution.
ma deuxième fonction que j'ai créé est la suivante:
function items(PDO $bdd, $form_id){
$query = "SELECT item_titre FROM items JOIN formation ON items.form_id=formation.form_id";
$resultat = $bdd->prepare($query);
$resultat->execute();
$items = $resultat->fetch();
Merci d'avance pour votre aide
J'ai créé via php myadmin 2 tables j'ai affiché à l'aide du code suivant les données de la table 1:
if ($formations) {
?>
<table align="center" border="1">
<?php
foreach ($formations as $formation) {
?>
<thead>
<tr>
<th>form_id</th>
<th>form_titre</th>
<th>form_nb_jour</th>
<th>form_reference</th>
<th>form_prix</th>
<th>form_objectifs</th>
<th>form_participants</th>
<th>form_prerequis</th>
<th>items</th>
</tr>
</thead>
<tbody>
<tr>
<td><?=$formation->form_id?></td>
<td><?=$formation->form_titre?></td>
<td><?=$formation->form_nb_jour?></td>
<td><?=$formation->form_reference?></td>
<td><?=$formation->form_prix?></td>
<td><?=$formation->form_objectifs?></td>
<td><?=$formation->form_participants?></td>
<td><?=$formation->form_prerequis?></td>
<td><?=$item->item_titre?></td>
</tr>
</tbody>
<?php
}
}
else {
echo "<tr><td colspan='7'>Aucun résultat</td></tr>";
}
?>
j'aimerai à présent rajouter une colonne de ma deuxième table a ce tableau, j'ai déjà créé une fonction qui contient la requête sql de la jointure et j'aimerai afficher le résultat de cette requête dans la nouvelle colonne de mon tableau et je ne trouve pas de solution.
ma deuxième fonction que j'ai créé est la suivante:
function items(PDO $bdd, $form_id){
$query = "SELECT item_titre FROM items JOIN formation ON items.form_id=formation.form_id";
$resultat = $bdd->prepare($query);
$resultat->execute();
$items = $resultat->fetch();
Merci d'avance pour votre aide