用于在液晶电视中显示日程信息的自动分页

时间:2014-10-05 16:05:34

标签: javascript php html mysql pagination

我想在液晶电视上显示一些调度信息。为此,我设法创建一个显示数据的php页面。我每页设置10个数据用于显示,因为它有分页代码。

它运作良好,但我想自动运行该分页;这意味着几秒钟后页面会自动转到第二页然后转到第三页等,并在到达最后一页后开始循环。我不知道如何实现这一点。

以下是参考代码:

Pagination.php: -

<?php
$con = mysql_connect("localhost","root",""); 
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
  mysql_select_db("test", $con); //Provide database name which has our data for pagination.

  $query = mysql_query("select CTime, Venue, Lecturer, Subject, Course from schedule where TDate = CURRENT_DATE"); 
  $total_rows = mysql_num_rows($query);

  $base_url = 'https://localhost/page/';    
  $per_page = 10;                           
  $num_links = 8;                           
  $total_rows = $total_rows; 
  $cur_page = 1;                           


    if(isset($_GET['page']))
    {
      $cur_page = $_GET['page'];
      $cur_page = ($cur_page < 1)? 1 : $cur_page;            
    }

    $offset = ($cur_page-1)*$per_page;             
    $pages = ceil($total_rows/$per_page);              

    $start = (($cur_page - $num_links) > 0) ? ($cur_page - ($num_links - 1)) : 1;
    $end   = (($cur_page + $num_links) < $pages) ? ($cur_page + $num_links) : $pages;

    $res = mysql_query("select CTime, Venue, Lecturer, Subject, Course from schedule where TDate = CURRENT_DATE LIMIT ".$per_page." OFFSET ".$offset);

 mysql_close($con);
  ?>

Index.php: -

<!DOCTYPE html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="eng">
    <head>
    <?php

    ?>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>Pagination</title>
        <link href="column-options.css" rel="stylesheet" type="text/css" />
        </head>
    <body>
        <div id="kotak">    
    <?php

    include("pagination.php"); 


        if(isset($res))
        {


            echo '<table class="stat">';           
            echo'<th>Class Duration</th><th>Venue</th><th>Lecturer</th><th>Subject</th><th>Course</th></tr>'; 
            while($result = mysql_fetch_assoc($res))
            {
              echo '<tr>';
              echo '<td>'.$result['CTime'].'</td>'.'<td>'.$result['Venue'].'</td>'.'<td>'.$result['Lecturer'].'</td>'.'<td>'.$result['Subject'].'</td>'.'<td>'.$result['Course'].'</td>' ;
              echo '</tr>';
            }
            echo '</table>';

        }

    ?>
    </div>

    <div id="pagination">
        <div id="pagiCount">
            <?php

                if(isset($pages))

                {  
                    if($pages > 1)        
                    {    if($cur_page > $num_links)    
                        {   $dir = "first";
                            echo '<span id="prev"> <a href="'.$_SERVER['PHP_SELF'].'?page='.(1).'">'.$dir.'</a> </span>';
                        }
                       if($cur_page > 1) 
                        {
                            $dir = "prev";
                            echo '<span id="prev"> <a href="'.$_SERVER['PHP_SELF'].'?page='.($cur_page-1).'">'.$dir.'</a> </span>';
                        }                 

                        for($x=$start ; $x<=$end ;$x++)
                        {

                            echo ($x == $cur_page) ? '<strong>'.$x.'</strong> ':'<a href="'.$_SERVER['PHP_SELF'].'?page='.$x.'">'.$x.'</a> ';
                        }
                        if($cur_page < $pages )
                        {   $dir = "next";
                            echo '<span id="next"> <a href="'.$_SERVER['PHP_SELF'].'?page='.($cur_page+1).'">'.$dir.'</a> </span>';
                        }
                        if($cur_page < ($pages-$num_links) )
                        {   $dir = "last";

                            echo '<a href="'.$_SERVER['PHP_SELF'].'?page='.$pages.'">'.$dir.'</a> '; 
                        }   
                    }
                }
            ?>
        </div>
    </div>  
</body>
</html>

1 个答案:

答案 0 :(得分:0)

我找到了解决方案:

header('Refresh: 10; URL='.$_SERVER['PHP_SELF'].'?page='.$nextpage);