0
내가하려는 것은 카테고리를 한 번만 인쇄 한 다음 포럼을 인쇄하는 것입니다. 하지만 그 대신 인쇄 범주를 여러 번 및 포럼 ...루프 카테고리가 해당 포럼에 한 번 있습니다.
내 테이블 :
categories
id | name | disp_position
forums
id | cat_id | name | description | disp_position
코드 :
$lastCatID = null;
$query = $db->query("SELECT f.id AS fid, f.cat_id, f.name AS forum_name, c.name AS cat_name FROM categories c
INNER JOIN forums f
ORDER BY c.disp_position, c.id, f.disp_position");
<?php foreach($query as $row): ?>
<div class="catname">
<?php
if ($lastCatID != $row['cat_id']) {
echo '<h1>' . $row['cat_name'] . '</h1>';
$lastCatID = $row['cat_id'];
}
?>
</div>
<p><?=$row['forum_name']?></p>
<?php endforeach ?>
그래서 나는 2 종류가 있습니다
테스트 카테고리를 (id 1) 및 테스트 범주 2 (id 2)
및이 포럼 :
(1, 1, 'News & Announcements', 'Official announcements are posted here.', 1),
(2, 1, 'Proposals', 'Propose and help us improve.', 5),
(3, 2, 'Gameplay', 'Talk about the game here.', 3),
(4, 2, 'Off Topic', 'Discuss all things not related to the game.', 4),
(5, 1, 'General', 'This forum is for general discussion.', 2),
(6, 1, 'Help & Support', 'Players helping players.', 6),
(7, 2, 'Bug Report', 'Found a bug? Help us squash it by reporting it here!', 7),
(8, 1, 'Trade', 'Sell your items or buy something you need.', 8);
출력 : 귀하는 USING 절을 누락 또는 WHERE 절에 조인
Test category
News & Announcements
General
Test category
Gameplay
Off Topic
Test category
Proposals
Help & Support
Test category
Bug Report
Test category
Trade
News & Announcements
General
Test category 2
Gameplay
Off Topic
Test category 2
Proposals
Help & Support
Test category 2
Bug Report
Test category 2
Trade