2017-06-03 5 views
-1

私は1つのテレビダッシュボード(タッチなし)を持っています。データベースPHP/MySQLから動的に情報を表示したい。 しかし、ここでは問題があります:テーブルの行が画面の高さを超えたとき、自動的に2ページ目を表示したい、10秒後に最初のページに自動的に戻りたいと思います。すべてのループモード。それは可能ですか?php html 1つのテレビダッシュボードに大きなダイナミックテーブルのデータを表示

ありがとうございます。

私はこのようなコードを持っている:

<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> 

あなたは私助けてくださいことはできますか? <head>代わりに

+0

簡単な解決策は、2つのページを作成してから10秒後に2番目のページへのメタリフレッシュとの直接の操作を行い、その後、反対バックすることです。 – Andreas

+0

' ' – Andreas

+0

?それはそれが機能しないという意味ですか?私は問題を理解していません – Andreas

答えて

0

この:

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

これはにページのURLを更新するために、GETメソッドとメタリフレッシュを使用しています?p = 1または?p = 2とし、ページに応じて表示リストの異なる部分を読み込む。
"ページ1"の半分のデータと "ページ2"の残りの半分が表示されます。

+0

私はお試しください。ありがとうございました。連絡を取り合う。 –

+0

@ Cristian-AngeloLungu私が気づいたことの1つは、おそらく "ページ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行以上の場合は、表示するページが1つだけ必要です.30より小さい場合は両方のページが必要ですか?その場合は、最初にデータベースに接続し、エントリ数を数えなければなりません。そして> 30が上記のようになると、ページを更新するだけです。それは私がうまくいくと思います。上記の私の答えを編集して、私が何を意味するのかを見ることができます。 – Andreas

+0

@アンドレアス、それは働いています。はい、 "30"はスクリーンに収まるので、 "30"はマジックナンバーです。行<= 30の場合、1ページしか必要ない場合、行> 30を2ページまたは3ページに分割する必要がある場合。あなたのスクリプトは大丈夫です。あなたのお時間をありがとうございました。 –

+0

3ページが必要な場合は、数行を追加するだけで、3ページが得られます。問題ない :-) – Andreas

関連する問題