2016-12-01 73 views
1

所以我一直在做一个homelab仪表板,我需要知道如何在显示我的php数组后添加一个响应式的“显示更多”按钮。我对开发相当陌生,而且更像是一种爱好。以下是我目前如何设置它,但是如果我在torrent数组中有超过15个项目,它会变得冗长。任何的意见都将会有帮助。查看更多按钮为php阵列

<div class="row"> 
<!--Downloading Section--> 
<div class="col-lg-6 col-md-3 col-sm-12 col-xs-12"> 
    <div class="info-box blue-bg"> 
     <h3>Downloading <span class="speeds"> 
     <?php 
      if ($client == "qbittorent"){ 
       echo round(intval($global_info['dl_info_speed'])/1000, 2) . " kB/s"; 
      } elseif ($client == "transmission"){ 
       echo round(intval($global_info['downloadSpeed'])/1000, 2) . " kB/s"; 
      } 
     ?> 
     </span></h3> 
     <?php 
      if($torrents == null){ 
       echo "There was a problem fetching torrents."; 
      } else { 
       if ($client == "qbittorrent"){ 
        foreach($torrents as $torrent){ 
         if($torrent['state'] == "downloading"){ 
          echo $torrent['name'] . "<br>"; 
         } 
        } 
       } elseif ($client == "transmission"){ 
        foreach($torrents['torrents'] as $torrent){ 
         if($torrent['status'] == "4"){ 
          echo $torrent['name'] . "<br>"; 
         } 
        } 
       } 
      } 
     ?> 
    </div><!--/.info-box--> 
</div><!--/.col--> 
+0

你可以用CSS隐藏输出,并添加一个按钮,该按钮对JavaScript做出反应以放大隐藏的部分。 –

回答

0

有两种方法可以做到这一点。

  • AJAX:使用JavaScript来检测单击按钮时,然后提交一个AJAX调用的结果页面,然后将结果添加到页面
  • 可见切换:打印出所有的结果,如你现在正在做,但在15之后隐藏任何东西(即style="display:none")。然后使用javascript检测按钮单击,并切换可见性以显示隐藏的结果。
0

你不能有一个“PHP显示更多按钮”。 PHP是执行服务器端,你需要Javascript来实现这一点。

您将使用Javascript来执行一个Ajax请求到一个PHP页面,该页面可以生成您的“更多项目”需要的内容,然后将其返回到Javascript函数,然后附加您的HTML。