2016-10-10 3 views
0

Hier ist meine Frage, wie kann ich die topic_id = 27 innerhalb der cat_id = 2 bekommen?Zeige letzte Eingabe auf einem LINKEN JOIN

Auch das andere "neue" Thema wie ID = 24

Vielen Dank für alle, und sorry für mein nicht-Wissen und mein Englisch :-)

Result in HTML ][DataBase] Code

$cat = $bdd->prepare('SELECT * from categories LEFT JOIN topics on topic_cat = cat_id group by cat_id limit 5 '); 
$cat_show_list = $cat->execute(); 



echo '<table border="1"> 
    <tr> 
     <th>5 Dernières catégories</th> 
     <th>Dernier topic</th> 
    </tr>'; 

while ($cat_show_list = $cat->fetch(PDO::FETCH_ORI_FIRST)){ 
echo '<tr>'; 
echo '<td class="#">'; 
echo '<h4><a href="category.php?id='. $cat_show_list['cat_id'].'">'. $cat_show_list['cat_name'].'</a></h4>'.''; 
echo '<a> '.$cat_show_list['cat_description'] . '</a>'; 
echo '</td>'; 
echo '<td>'. $cat_show_list['topic_subject']; 
echo '</tr>'; 

} 
$cat->closeCursor(); 
+2

poste deinen Code als tatsächlichen Code, bitte nicht als screnshot. –

+0

Ja, tut mir leid :) –

Antwort

0

Die SQL-Abfrage war

SELECT 
    categories.*, 
    (SELECT topics.topic_subject 
    FROM topics 
    WHERE topics.topic_cat = categories.cat_id 
    ORDER BY topics.topic_date DESC 
    LIMIT 1) AS category_last_subject 
FROM 
    categories 
ORDER BY 
    categories.cat_id DESC 
LIMIT 5 
Verwandte Themen