2016-10-10 2 views
0

여기 내 질문입니다. topic_id = 27cat_id = 2 안에 어떻게 가져올 수 있습니까?LEFT JOIN의 마지막 입력 표시

또한 내하지 않은 지식과 내 영어 :-)에 대한 ID = 24

모든 주셔서 감사합니다, 미안 같은 다른 "새로운"주제

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

코드를 실제 코드로 게시하십시오. screnshot이 아니십시오. –

+0

예, 죄송합니다. :) –

답변

0

SQL 쿼리는

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 
입니다.