Page 1 of 1
Traverse between pages - getting records from mysql database
Posted: Sat Jun 11, 2005 1:46 am
by asanga
I need to traverse between pages by getting records from mysql database. its fine I can filter data from the database I can travese But I couldn't stop after all records are displayed. pls help me.
Posted: Sat Jun 11, 2005 3:11 am
by anjanesh
Code: Select all
$PageNo = $_GET['pg'];
$RowsPerPage = 10;
$StartRecord = ($PageNo-1)*$RowsPerPage;
$SQL = "SELECT * FROM `tablename` WHERE $Condition");
$Res = mysql_query($SQL);
$TotalCount = mysql_num_rows($Res);
$MaxPages = 25;
$StartPgNo = (ceil($PageNo / $MaxPages) * $MaxPages) - $MaxPages +1;
$LastPgNo = ceil($TotalCount / $RowsPerPage);
$StopPgNo = min($LastPgNo,$StartPgNo + $MaxPages);
$SQL = "
SELECT * FROM `tablename` WHERE $Condition
LIMIT $StartRecord,$RowsPerPage
";
$Res = mysql_query($SQL) or die(mysql_error());