1

我想列出每个类别的每个类别以及每个类别下面的每个常见问题解答。现在下面的代码只是按类别列出所有问答,而不是类别名称。有一个简单的解决方法吗?我是一个完全的新手,非常感谢一些帮助!

<? $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>
4

1 回答 1

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>
于 2012-10-19T02:30:19.083 回答