我想列出每个类别以及每个类别的每个常见问题解答q& a。现在,下面的代码只按类别列出所有q& a,但不列出类别名称。这有一个简单的解决方案吗?我是一个全新的人,真的很感激一些帮助!
<? $result = sqlite_query($db, "SELECT * FROM faqs ORDER BY faqcategory DESC");
while($row = sqlite_fetch_array($result)) {?>
<div class="midBoxContent">
<ul>
<li><?php echo $row['faqquestion'];?></li>
</ul>
<p><?php echo $row['faqanswer']; ?></p>
答案 0 :(得分:0)
<? $faqc = "";
$result = sqlite_query($db, "SELECT * FROM faqs ORDER BY faqcategory DESC");
while($row = sqlite_fetch_array($result)) {?>
<?php
// check if the category is changing...
if ($faqc != $row['faqcategory']){
// it's changed, write it out..
echo $row['faqcategory'];
$faqc = $row['faqcategory'];
}
?>
<div class="midBoxContent">
<ul>
<li><?php echo $row['faqquestion'];?></li>
</ul>
<p><?php echo $row['faqanswer']; ?></p>