我正在尝试从一个表中选择多行,具体取决于另一个表中给出的 ID。
我已经使用下面的代码进行了一半的工作,但是根据分配给它的不同标签的数量,它会多次回显每个博客,我该怎么做才能在博客文章的一份副本上显示多个标签?
$sqlCommand = "SELECT blogid, blogtitle, content, blogtime, category, blogseourl, author FROM blog ORDER BY blogtime DESC";
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error());
$blogDisplay = '';
while ($row = mysqli_fetch_array($query)) {
$blogid = $row["blogid"];
$blogtitle = $row["blogtitle"];
$content = $row["content"];
$blogtime = $row["blogtime"];
$category = $row["category"];
$blogseourl = $row["blogseourl"];
$author = $row["author"];
$contentshort = substr($content, 0, 250);
$sqlCommand2 = "SELECT tag FROM blogtags WHERE blogid='$blogid'";
$query2 = mysqli_query($myConnection, $sqlCommand2) or die (mysqli_error());
while ($row = mysqli_fetch_array($query2)) {
$tag = $row['tag'];
$blogDisplay .= '<h1><a href="/blog/'. $blogseourl .'"> ' . $blogtitle . ' </a></h1> ' . $contentshort . '... <a href="/blog/'. $blogseourl .'">Read More...</a><br /><br /> ' . $author . ' posted on ' . $blogtime . ' | Category: ' . $category . ' | Tags: ' . $tag . ' | <a href="/blog/'. $blogseourl .'#disqus_thread"></a>';
}
}
mysqli_free_result($query);
因此,除了为每个标签回显多个 $blogDisplay 之外,一切都正常工作。
有人有什么想法吗?