如何使它显示回声

时间:2018-04-24 07:32:10

标签: php mysql

我正在制作一个论坛,有点练习我的技能,但我正在努力让它显示正确的东西。在这里,你看到我的代码解释了我想要的和我拥有的东西。

此代码将显示电路板列表:

<?php
  $boardds = $app->get_boards();
  foreach ($boardds as $board) {
   if($board['url'] == $url[1]){
    $actiefboardid = $board['id'];
    echo '<li style="background-color:lightgray;"><a href=""'.$board['url'].'">' . $board['topic'] . '</a></li>';
    } else {
     echo '<li><a href="'.$board['url'].'">' . $board['topic'] . '</a></li>'; 
    }

  }
?>

之后在代码中我将显示所有&#39;主题&#39;根据我们所在的董事会,如下:

<?php
  echo "<div class='tab-pane' id='activity'>";
  echo "<div class='post clearfix'>";
  $toppic = $app->get_topics($actiefboardid); <--- here I am displaying the records based on $actiefboardid
  foreach($toppic as $topic){
    echo "<div class='user-block'>";
       if(file_exists('assets/images/profielfotos/'.$topic['klant_id'])) { ..... ect

现在我希望它显示类似&#34;这个董事会没有主题&#34;当没有该董事会的记录时。

1 个答案:

答案 0 :(得分:0)

应用如下所示的count()条件: -

$toppic = $app->get_topics($actiefboardid);

if(count($toppic)>0){

  foreach($topic as $topic){
   //your code
  }
}else{

  echo "There are no topics on this board";
}

代码必须是这样的: -

<?php
    $boardds = $app->get_boards();
    if(isset($url[1])){
        foreach ($boardds as $board) {
            if($board['url'] == $url[1]){
                $actiefboardid = $board['id'];
                echo '<li style="background-color:lightgray;"><a href=""'.$board['url'].'">' . $board['topic'] . '</a></li>';
            } else {
                echo '<li><a href="'.$board['url'].'">' . $board['topic'] . '</a></li>'; 
            }
        }
    }else{
      echo "Please provide url 1";
    }
?>

和: -

<?php
    echo "<div class='tab-pane' id='activity'>";
    echo "<div class='post clearfix'>";
    if(isset($actiefboardid)){
        $toppic = $app->get_topics($actiefboardid); <--- here I am displaying the records based on $actiefboardid
        if(count($toppic) > 0){
            foreach($toppic as $topic){
                echo "<div class='user-block'>";
                if(file_exists('assets/images/profielfotos/'.$topic['klant_id'])) { //..... ect

                }
            }
        }
    }