2017-06-03 26 views
-1

我有一個電視儀表板(無需觸摸)。我想從數據庫PHP/MySQL中動態顯示一些信息。 但是,這是一個問題:當錶行超過屏幕高度時,我想自動顯示第二頁,10秒後我想自動返回第一頁。全部處於循環模式。這可能嗎?php html在一個電視儀表板中顯示大型動態表格數據

謝謝。

我有這樣的代碼:

<table class="table"> 
    <thead> 
     <tr> 
     <th id="th_left">Ticket ID</th> 
     <th id="th_left">Device Model</th> 
     <th id="th_left">Client Name</th> 
     </tr> 
    </thead> 



        <?php 
         for ($j=0; $j<count($to_display_list); $j++) { 
          $a = $to_display_list[$j]->status_id; 
        ?> 
    <tbody> 
     <tr> 
     <td><strong><?php echo $to_display_list[$j]->ticket_id ?></strong></td> 
     <td><strong><?php echo $to_display_list[$j]->device_model ?></strong></td> 
     <td><strong><?php echo $to_display_list[$j]->client_name ?></strong></td> 
     </tr> 
    </tbody> 
    <?php   
    } 
    ?> 
</table> 

你能幫助我嗎?

+0

一個簡單的解決辦法是在10秒後,以創建兩個頁面,然後做一個元刷新和直接到第二頁,那麼反回來。 – Andreas

+0

'' – Andreas

+0

好嗎?那是否意味着它不起作用?我不明白這個問題 – Andreas

回答

0

<head>的地方是:

<?php 
// connect to database here and do what you need to get the variable $to_display_list 

if(count($to_display_list)>=30){ 
    $page = $_GET['p']; 
    if($page == "1"){ 
     echo '<meta http-equiv="refresh" content="10; url=page.php?p=2">'; // replace page.php with your file name 
    }else{ 
     echo '<meta http-equiv="refresh" content="10; url=page.php?p=1">'; // replace page.php with your file name 
    } 
}else{ // less than 30 items, only display one page 
    echo '<meta http-equiv="refresh" content="10">'; 
} 
?> 

然後替換代碼的一部分,你有以上的有:

<table class="table"> 
    <thead> 
     <tr> 
     <th id="th_left">Ticket ID</th> 
     <th id="th_left">Device Model</th> 
     <th id="th_left">Client Name</th> 
     </tr> 
    </thead> 



<?php 
    if(count($to_display_list)>=30){ 
     if($page == "1"){ 
      for ($j=0; $j<count($to_display_list)/2; $j++) { 
      $a = $to_display_list[$j]->status_id;  
     }else{ 
      for ($j=count($to_display_list)/2; $j<count($to_display_list); $j++) { 
       $a = $to_display_list[$j]->status_id; 
      } 
    }else{ // less than 30 items to display 
     for ($j=0; $j<count($to_display_list); $j++) { 
      $a = $to_display_list[$j]->status_id; 
    } 
?> 
    <tbody> 
     <tr> 
     <td><strong><?php echo $to_display_list[$j]->ticket_id ?></strong></td> 
     <td><strong><?php echo $to_display_list[$j]->device_model ?></strong></td> 
     <td><strong><?php echo $to_display_list[$j]->client_name ?></strong></td> 
     </tr> 
    </tbody> 
    <?php   
    } 
    ?> 
</table> 

這將使用GET-方法和元刷新更新頁面的URL ?p = 1或?p = 2,並根據頁面讀取顯示列表的不同部分。
它將在「頁面1」上顯示一半數據,在「頁面2」上顯示另一半數據。

+0

我會試試。謝謝。保持聯繫。 –

+0

@ Cristian-AngeloLungu我注意到的一件事是,它可能會首先顯示「第2頁」,然後開始循環。如果這是一個問題,我可以改變它,所以它會啓動第1頁上的循環 – Andreas

+0

非常感謝Andreas。您的解決方案正在運行 –

0
Andreas, I have another question: 
    If there is less rows, mean "<30", why I need to display page.php?p=2 ??? 
    Below is my working code based on your answer (testing) 
    Thank you. 
<html> 
<head> 
    <?php 
     $page = $_GET['p']; 
     if($page == "1"){ 
      echo '<meta http-equiv="refresh" content="10; url=page.php?p=2">'; // replace page.php with your file name 
     }else{ 
      echo '<meta http-equiv="refresh" content="10; url=page.php?p=1">'; // replace page.php with your file name 
     } 
    ?> 
</head> 
<body> 
    <table border="1"> 
     <thead> 
      <tr> 
       <th>ID</th> 
       <th>NUMBER</th> 
       <th>MODEL</th> 
       <th>NAME</th> 
       <th>IN</th> 
       <th>START</th> 
       <th>PRICE</th> 
       <th>WAITING</th> 
       <th>DONE</th> 
       <th>TIME</th> 
      </tr> 
     </thead> 
     <tbody> 
     <?php 
      if($page == "1"){ 
       for ($x=0; $x<30/2; $x++) { 
     ?> 
      <tr> 
       <td><strong><?php echo $x ?></strong></td> 
       <td><strong>4545465</strong></td> 
       <td><strong>ANY MODEL</strong></td> 
       <td><strong>EMMET BROWN</strong></td>      
       <td></td> 
       <td></td> 
       <td></td> 
       <td>X</td> 
       <td></td> 
       <td>00:05:08</td> 
      </tr> 
     <?php } } else { 
      for ($x=30/2; $x<30; $x++) {  
     ?> 
      <tr> 
       <td><strong><?php echo $x ?></strong></td> 
       <td><strong>4545465</strong></td> 
       <td><strong>ANY MODEL</strong></td> 
       <td><strong>EMMET BROWN</strong></td>      
       <td></td> 
       <td></td> 
       <td></td> 
       <td>X</td> 
       <td></td> 
       <td>00:05:08</td> 
      </tr> 
     <?php }} ?> 
     </tbody> 
    </table> 
</body> 
</html> 
+0

好吧,魔術數字是30?如果超過30行,則只需要顯示一頁,如果小於30則需要兩頁?在這種情況下,您需要首先連接到數據庫並計算條目數量,然後如果> 30如上所述,否則只刷新頁面。這是我認爲會起作用的。我將在上面編輯我的答案,以便你能看到我的意思。 – Andreas

+0

@Andreas,它的工作。是的,「30」是幻數,因爲「30」線適合在屏幕上。當<= 30行只需要一頁時,當行> 30需要分成2或3頁時。你的腳本沒問題。非常感謝您的寶貴時間。 –

+0

如果你需要三頁,你只需要添加幾行,你會得到三頁。沒問題 :-) – Andreas