...

View Full Version : help with php pagination



Desii
08-15-2012, 01:08 AM
Hi, i want to have these options:

FirstPage | PreviousPage | 1 2 3 4 5 6 7 8 9 10 | NextPage | Last Page

and show 30 iteams per Page.

what my current coding is doing ryt now:

if i put down 30 iteams per page and it also shows me 30 Pages Links in pagination and effecting my layout.. but i only want 10 pages links to be displayed per page.. for example if users are on page 10 show: First Page | Prev Page | 10 11 12 13 14 15 16 17 18 19 20 | Next Page | Last Page


My Script isnt showing me options of FirstPage & LastPage in Pagination.

please help me out.


Index.php

<?php
include "includes/conn_db_connection.php";
include "includes/function_lib.php";

$catname=str_replace('_', ' ',$_REQUEST['catname']);
$data= mysql_fetch_object($s->getDataWithCondition('tbl_category', "category_name='$catname'"));
$catid=$data->category_id;

$catid=$_REQUEST['cat'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> All Latest <?=$catname?></title>
<META NAME="keywords" CONTENT="Latest <?=$catname?>">
<META NAME="description" CONTENT="Latest <?=$catname?> ">

<link rel="stylesheet" href="<?php echo $root; ?>/css/style.css" type="text/css" />
</head>
<body>
<div class="wrapper">
<?php include "includes/header.php";?>
<div class="wh"></div>
<div class="second_navigation">
<div style="width:30px; float:left; padding-top:5px; text-align:center;" ><img src="<?php echo $root; ?>/images/home.png" /></div>
<div style="width:20px; float:left; padding-top:1px; text-align:center;" ><img src="<?php echo $root; ?>/images/brea_arrow.png" /></div>
<ul> <li><a href="<?php echo $root;?>/index.php">Music</a></li>
<li><a href="<?php echo $root;?>/<?php echo strtolower(str_replace(' ', '_',$catname)); ?>-<?php echo $catid; ?>/"><?php echo ucfirst($catname); ?></a></li>
<li>All Albums</li>
</ul>
</div>
<!-- Header Part End HEre -->
<!-- Body Part Start HEre -->
<div class="body_part" style="padding-top:30px;">
<!-- Left Part Start HEre -->
<div class="left_part">
<!--Top Categories Section Start Here -->
<?php include "includes/left_category.php"; ?>
<!--first category end here -->
<!--second My account Section Start here-->
<?php include "includes/left_myaccount.php"; ?>
<!--second my account end here-->
<!--Google ADS Start here-->
<?php include "includes/left_ads.php"?>
<!--Google ADS end here-->
<!--Find us on Facebook end here-->
<?php include "includes/left_facebook.php"; ?>
<!--Find us on Facebook end here-->
<!--Top Categories Section End Here -->
</div>
<!-- Left Part end HEre -->
<!-- Right Part end HEre -->
<div class="middle_part_one">
<div class="hea_ajay" style="text-align:center;"> <?php echo strtoupper($catname); ?> ALL ALBUMS</div>
<div class="main" style="padding-top:0px;">
<div class="main" style="padding-top:7px; text-align:center;"> <?php include "includes/middle_top.php"?> </div>
<div class="wi">
<?php
include("includes/paging.php");
$ct=0;
$search2=" select cat.category_id,cat.category_name,alb.artist_id as all_artist_id,alb.album_id,alb.album_name,alb.cover_image_small,alb.album_tracks, alb.release_date, art.artist_id, art.artist_name from tbl_category as cat, tbl_album as alb, tbl_artist as art where cat.category_id=alb.category_id and alb.album_status = 'active' and art.artist_id IN (alb.artist_id) and cat.category_name='$catname' ORDER BY alb.album_id DESC ";
//paging code start
$itemPerPage=30;
$records = $search2;
$qry=getPagingQuery($records, $itemPerPage);
$search = $qry;
$search1 = mysql_query($qry);
$pageLink=getPagingLink($records,$itemPerPage,$qry,'');
$noUser = mysql_num_rows($search1);
//paging end here
$cqry=mysql_query($search) or die(mysql_error());
$num=mysql_num_rows($cqry);
if($num>0)
{
while( $cat_data=mysql_fetch_object($cqry) )
{

if(empty($cat_data->release_date)){ $rldate='unknown'; } else{ $rldate= date('Y', strtotime($cat_data->release_date)); }
?>
<div class="various" >
<div class="cd_cover">
<div class="imag1"><a href="<?php echo $root; ?>/<?php echo strtolower(str_replace(' ', '_',$catname)); ?>/album-<?php echo $cat_data->album_id;?>/<?php echo strtolower(str_replace(' ', '_',$cat_data->album_name));?>-<?php echo strtolower(str_replace(' ', '_',$cat_data->artist_name));?>/"><img src="<?php echo $root; ?>/<?php echo $cat_data->cover_image_small; ?>" height="76" width="76" /></a></div>
</div>
<div class="tetc">
<div class="ultimet"><a href="<?php echo $root; ?>/artist/<?php echo strtolower(str_replace(' ', '_',$cat_data->artist_name)); ?>-<?php echo $cat_data->artist_id; ?>/"><?php echo $cat_data->artist_name; ?></a></div>
<div class="ultimet"><a href="<?php echo $root; ?>/<?php echo strtolower(str_replace(' ', '_',$catname)); ?>/album-<?php echo $cat_data->album_id;?>/<?php echo strtolower(str_replace(' ', '_',$cat_data->album_name));?>-<?php echo strtolower(str_replace(' ', '_',$cat_data->artist_name));?>/"><?php echo $cat_data->album_name; ?></a></div>
<div class="ultimet"><?php echo $cat_data->album_tracks; ?> tracks</div>
<div class="ultimet"><?php $s->get_litners($cat_data->album_id); ?></div>
<div class="ultimet"><?php echo $rldate; ?>- <?php echo $cat_data->category_name; ?></div>
</div>
</div>
<?php $ct++; } } if($num==0) { ?>
<div style=" font-size:20px;color:#FF0000; height:35px;"> No Record Found in database </div>
<?php } ?>
</div>
</div>
<div class="main" >
<?php if($pageLink[1]) {?>

<strong><?php echo $pageLink[0]; ?></strong>
<div class="mi">
<ul>
<?php echo $pageLink[1]; ?>
</ul>
</div>
<div class="right_arrow"> <strong><?php echo $pageLink[2]; ?></strong>&nbsp;<img src="<?php echo $root;?>/images/righ.png" /> </div>
</div>
<div class="main_breadcum_right"></div>
</div>
<?php } ?>
</div>
<div class="main" style="padding-top:22px; padding-bottom:55px; text-align:center;"> <?php include "includes/middle_bottom.php"?> </div>
</div>
<!-- Right Part end HEre -->

<!-- Right Part Start Here -->

<div class="righta">
<!-- right search strart -->
<?php include "includes/right_search.php"; ?>
<!-- right search End -->

<!-- Right Top 10 Songs start -->
<?php include "includes/right_topsongs.php"; ?>
<!-- Right Top 10 Songs End -->

<!-- Right Sponsers start -->
<?php include "includes/right_sponsers.php"; ?>
<!-- Right Sponsers End -->
</div>
<!-- Right Part End Here -->
<!-- footer Start -->
<?php include "includes/footer.php"; ?>
<!-- footer End -->
</div>
</div>
</body>
</html>



Paging.php


<?php
global $offset;


function getPagingQuery($sql, $itemPerPage )
{


if (isset($_GET['page']) && (int)$_GET['page'] > 0) {
$page = (int)$_GET['page'];
} else {
$page = 1;
}

$offset = ($page - 1) * $itemPerPage;

return $sql . " LIMIT $offset, $itemPerPage";
}

function getPagingLink($sql, $itemPerPage , $strGet ='',$search_key)
{

global $db;
$result = mysql_query($sql);
$pagingLink = '';
$totalResults =mysql_num_rows($result);
$totalPages = ceil($totalResults / $itemPerPage);
$numLinks = $itemPerPage;
if ($totalPages > 1) {
include "includes/conn_db_connection.php";
$ID = $_REQUEST['catname'];
$self = $root."/".$ID."-all-albums";
$page_name=basename($_SERVER['PHP_SELF']);
if(isset($_REQUEST['profile_id'])!="")
{
$self=$HTTP_PATH.$page_name."?profile_id=".$_REQUEST['profile_id'];
}

if (isset($_GET['page']) && (int)$_GET['page'] > 0) {
$pageNumber = (int)$_GET['page'];
} else {
$pageNumber = 1;
}

if ($pageNumber > 1) {
$page = $pageNumber - 1;
if ($page > 1)
{
$prev = "<a class='pre_next' style='color:#444444; text-decoration:none;' href='$self/page-$page/'>Prev</a>";
}
else
{
$prev = "<a class='pre_next' style='color:#444444; text-decoration:none;' href='$self/page-$page/'>Prev</a>";
}
$first = "<a class='pre_next' style='color:#444444; text-decoration:none;' href='$self/page-1/'>First</a>";
}
$first = "<a class='pre_next' style='color:#444444; text-decoration:none;' href='$self/page-1/'>First</a>"; // nor 'first page' link



if ($pageNumber < $totalPages) {
$page = $pageNumber + 1;
$next = "<a class='pre_next' style='color:#444444; text-decoration:none;' href='$self/page-$page/'>Next</a>";
$last = "<a class='pre_next' style='color:#444444; text-decoration:none;' href='$self/page-$totalPages/'>Last</a>";
} else {
$next = "<a class='pre_next' style='color:#444444; text-decoration:none;' href='$self/page-$page/'>Next</a> ";
$last = "<a class='pre_next' style='color:#444444; text-decoration:none;' href='$self/page-$totalPages/'>Last</a>";
}

$start = $pageNumber - ($pageNumber % $numLinks) + 1;
$end = $start + $numLinks - 1;

$end = min($totalPages, $end);

$pagingLink = array();
for($page = $start; $page <= $end; $page++) {
if ($page == $pageNumber) {
$pagingLink[] = "<li><a class='no_link' style='color:Orange;'>$page </a> </li>"; // no need to create a link to current page
} else {
if ($page ==1) {
$pagingLink[] = " <li> <a class='no_link' style='color:Black; text-decoration:none;' href='$self/page-$page/'>$page</a> </li>";
} else {
$pagingLink[] = " <li> <a class='no_link' style='color:Black; text-decoration:none;' href='$self/page-$page/'>$page</a> </li>";
}
}

}

$pagingLink = implode(' ', $pagingLink);
//$pagingLink = $first .'&nbsp;&nbsp;&nbsp;'. $pagingLink .'&nbsp;&nbsp;&nbsp;'. $last;
}
return array($prev, $pagingLink, $next);
}
?>


and the CSS i want to use for Pagination is attached..


thanks in advance :thumbsup:

Fou-Lu
08-15-2012, 01:20 AM
You're going to have to format this code. It is illegible on a single line.
The CSS itself is irrelevant to the data you require.

Desii
08-15-2012, 01:27 AM
hi Fou-Lu
thanks for quick response. format is done now, sorry abt that

looking forward for your help :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum