得到一个很好的<li>

时间:2018-03-23 12:25:25

标签: php html css html-lists

我希望从数据库中获取的数据看起来与<li>的方式相同,但随后数据库的输出也显示出来。

how it looks like正如您所看到的那样,它将数据放在数据库中,并且我希望它与<li>'s

一样
<div class="row content">
      <ul class="nav nav-pills nav-stacked">
         <li class="active"><a href="#section1">Home</a></li>
         <li><a href="#section2">Friends</a></li>
         <li><a href="#section3">Family</a></li>
         <li><a href="#section3">Photos</a></li>
         <?php
         $toppics = $app->get_topics();
         foreach ($toppics as $topic) {
         echo $topic['onderwerp'] . '<br />';
         }
         ?>
   </ul><br>
</div>

1 个答案:

答案 0 :(得分:4)

<li>中输出您的输出:

foreach ($toppics as $topic) {
     echo '<li>' . $topic['onderwerp'] . '</li>';
}

// Each `onderwerp` in it's own <ul>
// BUT previous <ul> must be closed.
foreach ($toppics as $topic) {
     echo '<ul><li>' . $topic['onderwerp'] . '</li></ul>';
}

// dynamic href attribute
$i = 4;
foreach ($toppics as $topic) {
     echo '<li><a href="#section' . $i++ . '">' . $topic['onderwerp'] . '</a></li>';
}