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

Member Avatar for LastMitch

i'm trying configure pagination with my category menu, but it's not working.

What is not working? You mention that pagination is working smoothly? What did you do it to make it now working?

Member Avatar for diafol

Go to likeplum if you want to spend money on getting an answer. Alternatively, stay here and get some help for free.

//EDIT

to explain - a spammer was pushing likeplum before he got his posts deleted :)

Member Avatar for diafol

What is not working? You mention that pagination is working smoothly? What did you do it to make it now working?

Second that. we need more info.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.