Pagination help - URGENT - earn $5

Discussion in 'PHP' started by crazyryan, Feb 4, 2007.

  1. #1
    Hey, look at this site:
    http://www.proxy.gd/index.php

    If you click NEXT, it goes to index.php?page=2, and next again takes you to page=3 etc so on. However, it still links to page=4 even if there isn't actually a link, currently I've set it to show 1 link per page to show you. If there isn't page=4 then I don't want to link it.

    Also, if you go to index.php?sortby=link_added, the next URL is just index.php?sortby=link_added instead of &page=2.

    I'll reward $5 to whoever fixes these problems.

    <?
    
                    // Include database
    
    require '/home/proxygd/public_html/proxies/config.php';
    
    $perpage = 1;
    
    $q = 'SELECT * FROM links WHERE confirmed = \'yes\'';
    
    if (!empty($_GET['type'])) {
       $q .= ' AND link_type = \''. addslashes($_GET['type']) .'\'';
    }
    
    if (!empty($_GET['sortby'])) {
       $q .= ' ORDER BY '. addslashes($_GET['sortby']);
       if (!empty($_GET['order'])) {
          $q .= ' '. addslashes($_GET['order']);
       }
    }
    else {
       $q .= ' ORDER BY link_id DESC';
    }
    
    
            $total = mysql_num_rows(mysql_query($q));                        
    
    if (!empty($_GET['page'])) {
       if ($_GET['page'] == 1) {
            $start = 0;
         }
         else {
            $start = $perpage * ($_GET['page'] - 1);
         }
         $q .= ' LIMIT '. $start .', '. $perpage;
    }
    else {
       $q .= ' LIMIT '. $perpage;
    }
    
    $result = mysql_query($q) or die("Error in query " . mysql_error());
    
                    $numb = mysql_num_rows($result);
    
                    if ($numb > 0) {
    
                    while ($row = mysql_fetch_assoc($result)) {
    
                    // THIS IS THE PART WHERE YOU CAN MODIFY THE LINK OUTPUT
    
                    // DO NOT MODIFY ANY THING OUTSIDE OF THE FOLLOWING 4 LINES OR YOU WILL BREAK SOMETHING
    
                    echo "<p class=\"box\"><a href=\"$siteurl/$row[link_id]/\">$row[link_title]</a><br />";
    
                    echo "Description: " . $row['link_description'] . "<br />";
    
                    echo "Visitors: " . $row['link_visitors'] . "<br />";
    
                    echo "Type: " . $row['link_type'];
    
                    echo "</p>";
    
                    }
    
                    if ($pp > 1) {
    
                    $ts = 0;
    
                    foreach ($_GET as $key => $value) {
    
                        if ($key == "page") { $value--; }
    
                        if ($ts == 0) {
    
                        $ns .= "?" . $key . "=" . $value;
    
                        $ts++;
    
                        }
    
                        else {
    
                        $ns .= "&" . $key . "=" . $value;
    
                        $ts++;
    
                        }
    
                        }
    
                        echo "<a href=\"index.php" . $ns . "\">PREVIOUS</a>";
    
                    }
                    // Fix for pagination.
                    // PP was set to 0, causing equations to evaluate wrong.
                    if (($perpage * $pp) == "0") { $pp = "1"; }
                    // Fix for the pagination part 2
                    unset($ns);
                    if ($total > ($perpage * $pp)) {
                        $ts = 0;
                            foreach ($_GET as $key => $value) {
                                if ($key == "page") { $value++; }
                                if ($ts == 0) {
                                $ns .= "?" . $key . "=" . $value;
                                $ts++;
                                }        
                                else {
                                $ns .= "&" . $key . "=" . $value;
                                $ts++;
                                }
                            }
                            if (empty($ns) and $total > ($perpage * $pp)) { echo "<a href=\"index.php?page=2\">NEXT</a>"; }
                            if (!empty($ns) and $total > ($perpage * $pp)) { echo "<a href=\"index.php" . $ns . "\">NEXT</a>"; }
    
                        }
    
                    }
    
                    else {
    
                    echo "There are no links for the criteria specified";
    
                    }
    
                    ?>
    PHP:
     
    crazyryan, Feb 4, 2007 IP
  2. Icheb

    Icheb Peon

    Messages:
    1,092
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I'll trust that I'll receive payment for the fix I provided you yesterday.

    Try this

    if (!empty($ns) and $total > ($perpage * $pp + 1)) { echo "<a href=\"index.php" . $ns . "\">NEXT</a>"; }
    PHP:
     
    Icheb, Feb 4, 2007 IP
  3. crazyryan

    crazyryan Well-Known Member

    Messages:
    3,087
    Likes Received:
    165
    Best Answers:
    0
    Trophy Points:
    175
    #3
    Yeah you will, I'll send it in 2-3 hrs .. I'm doing coursework right now. I'll try that in a bit also.
     
    crazyryan, Feb 4, 2007 IP
  4. MeetHere

    MeetHere Prominent Member

    Messages:
    15,399
    Likes Received:
    994
    Best Answers:
    0
    Trophy Points:
    330
    #4
    Has the problem fixed now?
     
    MeetHere, Feb 4, 2007 IP
  5. crazyryan

    crazyryan Well-Known Member

    Messages:
    3,087
    Likes Received:
    165
    Best Answers:
    0
    Trophy Points:
    175
    #5
    crazyryan, Feb 4, 2007 IP
  6. Icheb

    Icheb Peon

    Messages:
    1,092
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I have the solution, however I will wait until I have received payment for the previous fix until I post it here.
     
    Icheb, Feb 4, 2007 IP
  7. crazyryan

    crazyryan Well-Known Member

    Messages:
    3,087
    Likes Received:
    165
    Best Answers:
    0
    Trophy Points:
    175
    #7
    I just sent payment. :)
     
    crazyryan, Feb 4, 2007 IP