Menu
hi all,
Can anybody please give me an idea to display the database values, 5 rows in the first page and the next 5 rows as in the 2nd page.. etc..
thanks in advance..
[code=php]
$page=$_GET['page'];
$resultsPerPage=5;
$startResult=($page-1) * $resultsPerPage;
$sql="SELECT * FROM item LIMIT $startResult,$resultsPerPage";
[/code]
[code=php]
<?php
session_start();
if ($_SESSION['name'])
{
include('welcome.php');
include('mysql_connect.php');
//Test for the GET
if(!isset($_GET['page']) ){
$page=1;
}
else{
$page=$_GET['page'];
}
$resultsPerPage=5;
//SELECT * FROM item LIMIT 0,5
//SELECT * FROM item LIMIT 5,5
$startResult=($page-1) * $resultsPerPage;
$sql=mysql_query("SELECT * FROM announcement LIMIT $startResult,$resultsPerPage");
echo "<table border=1 align="center">";
while ($row=mysql_fetch_array($sql))
{
echo"<tr>";
echo"<td><font color="blue">".$row[0]."</font></td>";
echo"<td><font color="blue">".$row[1]."</font></td>";
echo"<td><font color="blue"><a href="view_announce.php?no=$row[0]">".$row[2]."</a></font></td>";
//echo"<td>".$row[3]."</td>";
echo "</tr>";
$row[0]++;
}
echo "</table>";
//several ways to do the "list of links" - the following is inelegant... plenty of room for improvement!
$previous=$page-1;
if($previous > 0){
echo "<a href="view_ann.php?page=$previous">Previous</a>";
}
//Current page - no link
echo "Page $page";
$next=$page+1;
echo "<a href="view_ann.php?page=$next">Next</a>";
mysql_close($q1);
}
else
echo "<meta http-equiv=refresh content=0;url=first.php?error=1>";
?>
[/code]
$page=1;
0.1.9 — BETA 6.2