Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Nov 2011
    Posts
    74
    Thanks
    4
    Thanked 0 Times in 0 Posts

    pagination for order by price issue

    Hy
    I have this code and I can't figure where is the issue.
    I click to order products by price, but when I click to page 2, 3, etc, it dosn't keep the price order.

    Thank you in advance

    PHP Code:
     <?php
               
    if(isset($_REQUEST['product_search']))
               {
                   
    $que_pr $Myfun->search_pr($_REQUEST['product_search']);
                   
    $count mysql_num_rows($que_pr);
                   if(
    $count 0){
                                   
    $paginationCount=getPagination($count);
                                 }
                   if(
    $count==0)
                   {
                     
    $No '"'.$_SESSION['search_word'].'" &nbsp;No Rezultate found !';  
                   }
               }
               else
               {
                   
    $que_pr $Myfun->view_pr();
                   
    $count mysql_num_rows($que_pr);
                   if(
    $count 0){
                                   
    $paginationCount=getPagination($count);
                                 }
                   if(
    $count==0)
                   {
                     
    $No '"'.$_SESSION['search_word'].'" &nbsp;No Rezultate found !';  
                   }
               }
              
    ?>
              <!-- Get Product list 
              <div id="pageData"></div>      --> 
              <?php    
            $condi 
    'order by p_price desc';        
            if(isset(
    $_SESSION['search_word']))
            {
             
    $keyword $_SESSION['search_word'];
             
    $condi "where p_name like '%$keyword%'";    
            }
            if(isset(
    $_SESSION['align']))
            {
            
    $align $_SESSION['align'];
            
    $condi 'order by p_price '.$align;
            }
                if(
    $count 0){
                    
        
    $tableName="products";        
        
    $targetpage "index.php";
        
        
    $query "SELECT COUNT(*) as num FROM $tableName $condi";
        
    $total_pages mysql_fetch_array(mysql_query($query));
        
    $Mycount mysql_num_rows(mysql_query($query));
        
    $total_pages $total_pages[num];
        
    $limit 15;
        if(isset(
    $_SESSION['showAll']))
        {
        
    $limit $_SESSION['showAll'];
        }
            
        
    $stages 2;
        
    $page mysql_escape_string($_GET['page']);
        if(
    $page){
            
    $start = ($page 1) * $limit
        }else{
            
    $start 0;    
            }    
        
        
    // Get page data
        
    $query1 "SELECT * FROM $tableName $condi 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'>";
            
                

            
    // Pages     
            
    if ($lastpage + ($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 + ($stages 2))    // Enough pages to hide a few?
            
    {
                
    // Beginning only hide later pages
                
    if($page + ($stages 2))        
                {
                    
    // $counter < ($stages * 2); >>>>>  DEVA ..... DOTS find out
                    
                    
    for ($counter 1$counter + ($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 - (+ ($stages 2)); $counter <= $lastpage$counter++)
                    {
                        if (
    $counter == $page){
                            
    $paginate.= "<span class='current'>$counter</span>";
                        }else{
                            
    $paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}                    
                    }
                }
            }
                        
                    
                
            
    $paginate.= "</div>";        
        
        
        }

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Most of this criteria is coming out of sessions, but you don't post anything to indicate session variables are ever set. This indicates you need to have $_SESSION['align'] set in order to control the asc/desc direction of the p_price.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    New Coder
    Join Date
    Nov 2011
    Posts
    74
    Thanks
    4
    Thanked 0 Times in 0 Posts
    This is what`s missing?
    If not, can you help me please?
    Thx

    PHP Code:
    if (in_array($session->get('p_price.sort'), $sort)) {
                
    $sql .= " order by " $session->get('p_price.sort') . " " . (($session->get('p_price.order') == 'desc') ? 'desc' 'asc');
            } else {
                
    $sql .= " order by p_price asc";
            } 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •