我的问题是我不会得到正确的记录。正如您所看到的,每个主题都有一个board_id,它需要显示正确的主板,但现在它只显示stel jezelf voor
,最后一条记录需要nieuws & events
数据库与董事会
主题数据库
显示记录的代码:
<?php
$toppic = $app->get_topics();
foreach($toppic as $topic){
echo '<div id="topic">';
echo '<div id="topicimg">';
if(file_exists('assets/images/profielfotos/'.$topic['klant_id'])) {
echo '<img class="img-circle" src="/assets/images/profielfotos/'.$topic['klant_id'].'/'.$topic['foto'].'" />';
} else {
echo '<i class="fa fa-fw fa-user img-circle"></i>';
}
echo '</div><div id="topictekst">';
echo '<b><a href="https://tom.lbmedia.nl/reactie"> '.$topic['topicnaam'].'</b></a>';
echo '<a> - ' . $topic['voornaam'] . " " . $topic['achternaam'] . '</a>' ;
echo '<a style="float:right; margin-top:15px;"> reacties</a> <span style="float:right; color:grey; margin-top:15px"class="fa fa-comment"></span>';
echo '<hr><a><span class="badge bg-red">' . $board['topic'] . '</span></a>';
echo '</div></div>';
}
?>
此代码的功能是:
public function get_boards(){
$getBoards = $this->database->query("SELECT * FROM boards ORDER BY id DESC");
$boards = $this->database->resultset();
return $boards;
}
public function get_topics(){
$getTopic = $this->database->query("
SELECT topics.*, klanten.foto, klanten.voornaam, klanten.achternaam FROM topics
LEFT JOIN klanten ON topics.klant_id=klanten.id
ORDER BY id ASC");
$topics = $this->database->resultset();
return $topics;
}
总结,我想要的:
我希望它能够以正确的主题展示合适的主板。正如您所看到的,销售页面有board_id 2
,因此需要显示&#39; Nieuws&amp;事件&#39;而不是&#39; stel jezelf voor&#39;
EXTRA
如果可能的话,我希望它能使整个记录/ div可以点击。有什么提示/技巧吗?
答案 0 :(得分:0)
我认为您正在尝试进行一些考虑,如JOIN
以下,您可以查看
SELECT boards.topic, topics.topicnaam
FROM topics
LEFT JOIN boards ON boards.id = topics.boards_id
ORDER BY topics.id ASC
如果有一个名为klanten
的表格,那么查询就像:
SELECT boards.topic, topics.topicnaam, klanten.foto
FROM topics
LEFT JOIN boards ON boards.id = topics.boards_id
LEFT JOIN klanten ON topics.ledenpagina_id = klanten.ledenpagina_id
GROUP BY topics.id
ORDER BY topics.id ASC