Results 1 to 2 of 2

Thread: Pagination Problem

  1. #1
    Join Date
    Jan 2012
    Posts
    8
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Pagination Problem

    Hey everyone,


    I am stressing out here trying to fix the pagination. Firstly, I just learn some basics of PHP recently so please go easy on me. So here is my problem,


    I am currently using CuteNews 1.5.3, and everything works okay so far except for the pagination where it is giving weird errors. I e-mailed the CuteNews team but they haven't got back to me for a long time so I decided to come here and post for help.


    Take a look at this example that outline the problem,


    [Prev] [1] [2] [3] [4] [Next]


    At page 2 of the news, the URL for page 2 is site.com/news.php?start_from=5. If I click on the [PREV] or [1], the URL will remain as site.com/news.php?start_from=5. However [3], [4] and [Next] work perfectly fine.


    If I go to page 3 of the news, the URL for page 3 is site.com/news.php?start_from=10. The [PREV] on this page works fine (it allows me to return to page 2) but the [1] URL will remain as site.com/news.php?start_from=10.


    This situation goes on for the rest of the page. To sum it up, basically the [1] URL will always be the same as the URL you are currently at. And the [PREV] URL will be the same as the URL you are currently at only if you are at page 2. The ideal URL that I should be getting when I am clicking on [1] or [PREV] will be site.com/news.php?start_from=0.


    This is the PHP code that affects the pagination,


    PHP Code:
        // Triggerred by $config_disable_pagination = TRUE
        
    if ($config_disable_pagination == 0)
        {
            
    // << Previous & Next >>
            
    $prev_next_msg $template_prev_next;

            
    //----------------------------------
            // Previous link
            //----------------------------------
            
    if ($start_from)
            {
                
    $prev $start_from $number;
                
    $URL $PHP_SELF build_uri('start_from,ucat,archive,subaction,id:comm_start_from', array($prev$ucat$url_archive$subaction$id));
                
    $URL hook('rewrite_active_news_plink'$URL);

                
    $prev_next_msg preg_replace("'\[prev-link\](.*?)\[/prev-link\]'si"'<a href="'.$URL.'">\\1</a> '$prev_next_msg);
            }
            else
            {
                
    $prev_next_msg preg_replace("'\[prev-link\](.*?)\[/prev-link\]'si""\\1"$prev_next_msg);
                
    $no_prev true;
            }

            
    //----------------------------------
            // Pages
            //----------------------------------
            
    $pages '';

            if (
    $number)
            {
                
    $pages_count        ceil($count_all $number);
                
    $pages_start_from   0;

                for(
    $j=1$j<= $pages_count$j++)
                {
                    if ( 
    $pages_start_from != $start_from)
                    {
                        
    $URL $PHP_SELF build_uri('start_from,ucat,archive,subaction,id:comm_start_from', array($pages_start_from$ucat$url_archive$subaction$id));
                        
    $URL hook('rewrite_active_news_link'$URL);

                        
    $pages .= '<a href="'.$URL.'">'.$j.'</a> ';
                    }
                    else 
    $pages .= '<strong>'.$j.'</strong> ';
                    
    $pages_start_from += $number;
                }
            }
            else
            {
                
    $no_next true;
                
    $no_prev true;
            }

            
    $prev_next_msg str_replace("{pages}"$pages$prev_next_msg);

            
    //----------------------------------
            // Next link  (typo here ... typo there... typos everywhere !)
            //----------------------------------
            
    if ($number $count_all and $i $count_all)
            {
                
    $URL $PHP_SELF build_uri('start_from,ucat,archive,subaction,id:comm_start_from', array($i$ucat$url_archive$subaction$id));
                
    $URL hook('rewrite_active_news_nlink'$URL);

                
    $prev_next_msg preg_replace("'\[next-link\](.*?)\[/next-link\]'si"'<a href="'.$URL.'">\\1</a>'$prev_next_msg);

            }
            else
            {
                
    $prev_next_msg preg_replace("'\[next-link\](.*?)\[/next-link\]'si""\\1"$prev_next_msg);
                
    $no_next TRUE;
            }

            if (!
    $no_prev or !$no_next) echo $prev_next_msg;

        } 

    This is the PHP code that outputs the pagination to my HTML page,


    PHP Code:
    <?php
    $number
    ="5";
    include(
    "/site/show_news.php");
    ?>

    Does anyone know how to solve it? Thanks!


    ADDITIONAL INFORMATION


    This is the PHP that forms the URI of the pagination, hope it helps.

    PHP Code:
    // make full URI (left & right parts)
    function build_uri($left$right$html 1)
    {
        global 
    $QUERY_STRING;

        
    $URI $DDR = array();
        list (
    $left$adds) = explode(':'$left);

        
    $ix 0;
        
    $ex spsep($left);
        
    $uq spsep($adds);

        
    // Main parameters GET
        
    if ($left && is_array($ex)) foreach ($ex as $v)
        {
            if (isset(
    $right[$ix]) && $right[$ix]) $URI$v ] = $right[$ix];
            
    $ix++;
        }

        
    // Enum not present, but in GLOBALS is set
        
    if ($adds && is_array($uq))
            foreach (
    $uq as $v)
                if (isset(
    $GLOBALS[$v]) && $GLOBALS[$v]) $URI$v ] = $GLOBALS[$v];

        
    // Import at url $QUERY_STRING
        
    $QUERY_STRING str_replace('&amp;''&'$QUERY_STRING);
        foreach ( 
    spsep($QUERY_STRING'&') as $qs )
        {
            list(
    $k$v) = explode('='$qs2);
            if (
    $k && $v && !isset($URI[$k])) $URI[$k] = $v;
        }

        
    // Encode new query
        
    foreach ($URI as $i => $v)
        {
            
    $DDR[] = urlencode($i)."=".str_replace('%2C'','urlencode($v));
        }

        
    $DDU implode(($html?'&amp;':'&'), $DDR);
        if (
    $DDU == false) return '?c';

        
    // Return true link
        
    return '?'.$DDU;

    Last edited by ShieldofChaos; 07-07-2013 at 11:18 AM.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,127
    Thanks
    44
    Thanked 3,228 Times in 3,189 Posts
    Blog Entries
    12

    Default

    Have you tried the advice given here:

    http://cutephp.com/forum/index.php?showtopic=43715

    ??
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Similar Threads

  1. Virtual Pagination problem
    By justinchrono in forum Dynamic Drive scripts help
    Replies: 5
    Last Post: 04-13-2010, 07:45 PM
  2. pagination by date problem
    By nickcrow in forum PHP
    Replies: 0
    Last Post: 01-12-2009, 10:30 AM
  3. Ajax Pagination script problem
    By torrent in forum Dynamic Drive scripts help
    Replies: 2
    Last Post: 11-09-2008, 08:33 PM
  4. Ajax Pagination script problem
    By Linda80 in forum Dynamic Drive scripts help
    Replies: 8
    Last Post: 08-25-2008, 05:38 PM
  5. Ajax Pagination Problem
    By rob12345 in forum Dynamic Drive scripts help
    Replies: 2
    Last Post: 03-03-2008, 02:50 PM

Bookmarks

Posting Permissions

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