homepage Welcome to WebmasterWorld Guest from 54.166.122.65
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
php category menu configure into pagination
pagination, menu, category
jhon_samuel



 
Msg#: 4582187 posted 10:17 am on Jun 7, 2013 (gmt 0)

hello,
i'm using this pagination script and it works smoothly , but i want to display products when i pressed my category menu(php created), this is the code ,i'm trying configure pagination with my category menu, but it's not working. please help me. i'm newbie in php.





<?php

include('connect.php');

if(isset($_GET['category']))

{
$category=$_GET['category'];

$qry="select * from datas_disp where category=$category ORDER BY ID DESC";

$res=mysql_query($qry);

$tableName="$res";

// if i pressed categorm menu "$tableName" want to get the category number and fetch datas from "datas_disp(table name)" , means at normal case datas fetch through the default pagination script($tableName="datas_disp";), but at the time of hitting the category menu , want to fetch datas accroding to the category number.


}


else

{

$tableName="datas_disp";

}

$targetpage = "index.php";
$limit = 9;

$query = "SELECT COUNT(*) as num FROM $tableName";
$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages = $total_pages['num'];

$stages = 3;
$page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1;
if($page){
$start = ($page - 1) * $limit;
}else{
$start = 0;
}

// Get page data
$query1 = "SELECT * FROM $tableName LIMIT $start, $limit";
$result = mysql_query($query1);

// Initial page num setup
if ($page == 0){$page = 1;}
$prev = $page - 1;
$next = $page + 1;
$lastpage = ceil($total_pages/$limit);
$LastPagem1 = $lastpage - 1;


$paginate = '';
if($lastpage > 1)
{




$paginate .= "<div class='paginate'>";
// Previous
if ($page > 1){
$paginate.= "<a href='$targetpage?page=$prev'>previous</a>";
}else{
$paginate.= "<span class='disabled'>previous</span>";}



// Pages
if ($lastpage < 7 + ($stages * 2))// Not enough pages to breaking it up
{
for ($counter = 1; $counter <= $lastpage; $counter++)
{
if ($counter == $page){
$paginate.= "<span class='current'>$counter</span>";
}else{
$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}
}
}
elseif($lastpage > 5 + ($stages * 2))// Enough pages to hide a few?
{
// Beginning only hide later pages
if($page < 1 + ($stages * 2))
{
for ($counter = 1; $counter < 4 + ($stages * 2); $counter++)
{
if ($counter == $page){
$paginate.= "<span class='current'>$counter</span>";
}else{
$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}
}
$paginate.= "...";
$paginate.= "<a href='$targetpage?page=$LastPagem1'>$LastPagem1</a>";
$paginate.= "<a href='$targetpage?page=$lastpage'>$lastpage</a>";
}
// Middle hide some front and some back
elseif($lastpage - ($stages * 2) > $page && $page > ($stages * 2))
{
$paginate.= "<a href='$targetpage?page=1'>1</a>";
$paginate.= "<a href='$targetpage?page=2'>2</a>";
$paginate.= "...";
for ($counter = $page - $stages; $counter <= $page + $stages; $counter++)
{
if ($counter == $page){
$paginate.= "<span class='current'>$counter</span>";
}else{
$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}
}
$paginate.= "...";
$paginate.= "<a href='$targetpage?page=$LastPagem1'>$LastPagem1</a>";
$paginate.= "<a href='$targetpage?page=$lastpage'>$lastpage</a>";
}
// End only hide early pages
else
{
$paginate.= "<a href='$targetpage?page=1'>1</a>";
$paginate.= "<a href='$targetpage?page=2'>2</a>";
$paginate.= "...";
for ($counter = $lastpage - (2 + ($stages * 2)); $counter <= $lastpage; $counter++)
{
if ($counter == $page){
$paginate.= "<span class='current'>$counter</span>";

}else{
$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}
}
}
}

// Next
if ($page < $counter - 1){
$paginate.= "<a href='$targetpage?page=$next'>next</a>";
}else{
$paginate.= "<span class='disabled'>next</span>";
}

$paginate.= "</div>";


}
echo $total_pages.' Results';
// pagination
echo $paginate;
?>

<table width="756" border="0" align="center">
<?php

$product_count=0;

while($row = mysql_fetch_assoc($result))
{

if($product_count==0)

{

print "<tr>";

}

else if($product_count%4==0)

{

print "</tr><tr>";

}

?>
<td>

<a href="<?php echo $row['image_path']; ?> "title=" <?php echo $row['Shop_name'];?>">

<img src="<?php echo $row['image_path']; ?> " alt="loading..." width="170" height="120"/></a>

<h5><?php echo $row['Shop_name'];?> </h5>

<h5><?php echo $row['brand_name'];?> </h5>

<h5><?php echo $row['ratings'];?> </h5>

<h5><a href="more_info.php?id=<?php echo $row['id']; ?>"><input type="button" class="edit" value="More Details"></a> </h5>
</td>


<?php
$product_count++;
}

?>


</tr>
</table>

<?php
echo $total_pages.' Results';
// pagination
echo $paginate;
?>


<!--------------------my category script is --------------
-->

<?php

$qry_category="select * from category";

$res_category=mysql_query($qry_category);

while($r_category=mysql_fetch_assoc($res_category))

{

$url=$_SERVER['PHP_SELF']."?category=".$r_category['id'];

print '<li class="sliding-element"><a href="'.$url.'">'.$r_category['name'].'</a></li>';

}

?>



<!--my database design is -->


table 1 : name :- datas_disp

inside the datas_disp -: id , product_name , shop_name , category , image_path
1 camera excel 1 images/canon 7d.jpg
2 mobile sony 2 images/sony.jpg



table 2 : name:- category

inside the category : id , category
1 camera
2 mobile

 

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved