View Full Version : Making Next/Previous Buttons..
Mc Ghoush
Sun 12th Aug '01, 10:03am
Hi again ...
What I want to know this time is how to make Next/Previous bottons in my GuestBook...
I want each page to display 20 rowsof my database ...
Thanx for your co-opration...
Mark Hensler
Sun 12th Aug '01, 1:16pm
// num to display per page
// the more records per page, the slower the page will load
$PerPage = 10;
// Number of page links displayed (on either side of current page)
$Page_Links = 2;
if ($pageNum < 1 || !$pageNum) $pageNum = 1;
/*****************************************/
function Do_Links($querystring) {
// This function prints the pagenated links for the resuls.
global $PerPage, $Page_Links, $pageNum, $num_rows;
$num_pages = ceil($num_rows / $PerPage);
$start = ($pageNum > ($Page_Links + 1)) ? ($pageNum - $Page_Links) : 1;
$end = ($num_pages > ($pageNum + $Page_Links)) ? ($pageNum + $Page_Links) : $num_pages;
echo<<<myHTML
<table border=0 cellpadding=0 cellspacing=0 align=center>
<tr>
<td>
<font size=2 face=arial>
<a href="profile_admin.php3?pageNum=1&$querystring">First</a>
myHTML;
for ($i=$start; $i<$end; $i++) {
if ($i == $pageNum)
echo "\t<b>$i</b>\n";
else
echo "\t<a href=\"profile_admin.php3?pageNum=$i&$querystring\">$i</a>\n";
}
if ($end == $pageNum)
echo "<b>$end</b>\n";
else
echo "<a href=\"profile_admin.php3?pageNum=$end&$querystring\">$end</a>\n";
echo<<<myHTML
<a href="profile_admin.php3?pageNum=$num_pages&$querystring">Last</a>
</font>
</td>
</tr>
</table>
myHTML;
} //END Do_Links()
/*****************************************/
// BUILD/EXECUTE QUERY
// PUT RESULTS IN $result
if ($num_rows == 0) {
// no records found
// perhaps you should tell the user...
}
else {
// where do we start?
$pageNum = (isset($HTTP_POST_VARS["sid"])) ? 1 : $HTTP_GET_VARS["pageNum"];
$pageNum = ($pageNum < 1) ? 1 : $pageNum;
$start = $PerPage * ($pageNum - 1);
// go there!
mysql_data_seek($result, $start);
}
//pagenate it!
Do_Links($querystring);
// Now loop through the records
for ($i=0; $i<$PerPage; $i++) {
if ($tmp = mysql_fetch_array($result)) {
// Do ya thang!
} //END if ($tmp = mysql_fetch_array($result))
} //END for ($i=0; $i<$PerPage; $i++)
//pagenate it!
Do_Links($querystring);
Mc Ghoush
Mon 13th Aug '01, 6:59am
Thank you Max Albert...
vBulletin® v3.8.0 Beta 4, Copyright ©2000-2008, Jelsoft Enterprises Ltd.