Automatic pagination for displaying schedule information in
Posted: Mon Oct 06, 2014 6:12 am
I want to display some scheduling information on LCD TV. For this i manage to create a php page that display the data. I set 10 data per page for display, for this have the pagination code. its working well but i want to run that pagination automatically that means automatically after few seconds the page turns to second page then third page etc..and starts back the cycle once it reached the last page. but i don't know how to implement this. please can anyone help me on this. below are the code for reference:
pagination.php;-
$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);
?>
[/syntax]
index.php:-
I hope someone can help me to get this working. Thank you.
pagination.php;-
Code: Select all
<?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;
}
[syntax=php]$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);
?>
[/syntax]
index.php:-
Code: Select all
<!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>