Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Results 1 to 3 of 3

Thread: Pagination

  1. #1
    Join Date
    Jan 2009
    Location
    UK
    Posts
    42
    Tokens
    0

    Default Pagination

    I have this script:

    PHP Code:
    <?php
    session_start
    ();
    require (
    "connect.php");
    require(
    "functions.php"); 
    include(
    "template/header.php");

        
    $username $_SESSION['username'];
        
    $uid $_SESSION['id'];

        
    $cat $_GET['layouts'];

        
    $uid $_SESSION['id'];
        if(
    $cat == "none"){
        
    $result mysql_query("SELECT * from layouts ORDER BY `id` ASC");   
        }else{
        
    $result mysql_query("SELECT * from layouts WHERE categoryID='$cat'");
        }

        while(
    $list mysql_fetch_array$result )){

    $no_results TRUE;   // No results found yet
    $howmany    4;     // Return 10 results per query
     
    // Set default starting point of query to 0, or, if set, to $_GET['rs']
    $row_start  = (isset($_GET['rs'])) ? $_GET['rs'] : 0;
     
     
    // Do our SQL query, with something like LIMIT 0, 10
    $sql    "SELECT SQL_CALC_FOUND_ROWS title, previewlink, image FROM layouts LIMIT "$row_start .", "$howmany ."";
    $result mysql_query($sql);
     
     
    // Get the number of rows that would have been returned WITHOUT a limit clause, to be used later for paging.
    $count_sql        "SELECT FOUND_ROWS() AS total";
    $count_sql_result mysql_query($count_sql);
    $count_row       mysql_fetch_array($count_sql_result);
    $count_result       $count_row['total'];
     
    // Start looping through our result set
    while($row mysql_fetch_array($result)) {
        
    $no_results FALSE;
     
        
    // Save results of query to $line_output
        
    $line_output .= "


           <style>.button {
            margin-top: 0px;
        display:block;
        width:250px;
        height:50px;
        text-indent:-9999px;
        margin-left: 300px;
        }
        .button a {
        display:block;
        width:100%;
        height:100%;
        background:url(images/save.png) no-repeat top left;
        outline:none;
        }
        .button a:hover {
        background-position:0 -50px;
        }
        .button2 {
        margin-top: 0px;
        display:block;
        width:250px;
        height:50px;
        text-indent:-9999px;
        margin-left: 300px;
        }
        .button2 a {
        display:block;
        width:100%;
        height:100%;
        background:url(images/preview.png) no-repeat top left;
        outline:none;
        }
        .button2 a:hover {
        background-position:0 -50px;
        }
        #cats {
        width: 100px;
        height: 100px;
        margin: 5px;
        float: left;
        margin-left: 50px;
        }
        #layouts {
        background: url('images/backdrop.png');
        width: 609px;
        height: 190px;
        margin-left: 50px;
        }
        #next {
        margin-left: 50px;
        }
        </style>"
    ;
            echo 
    "<div id=\"layouts\"><br/><br/><div id=\"cats\"><img align=\"left\" src=\"images/";
            echo 
    $row['image'];
            echo 
    "\" width=\"100px\" height=\"100px\" border=\"1px\">";
            echo 
    $row['title'];
            echo 
    "</div><p class=\"button2\">";
            echo 
    "<a href=\"";
        echo 
    "twitterpreview.php?image=images/";
            echo 
    $row['image'];
            echo 
    "\" target=_blank\">";
            echo 
    "Preview Twitter Background";
            echo 
    "</a> ";
            echo 
    "</p>";
            echo 
    "<p class=\"button\">";
            echo 
    "<a href=\"";
            echo 
    "downloadimage.php?image=images/";
            echo 
    $row['image'];
            echo 
    "\">";
            echo 
    "Save Image";
            echo 
    "</a> ";
            echo 
    "</p></div>";
    }}
    // Don't bother building paging if we don't have records
    if ($no_results) {
        
    $line_output "No records found...";
        
    $page_output "";
    }
    else {
        
    // Build <prev> and <next> links and save to $page_output
        
    $rs_prev $row_start $howmany// where would prev page start, given current start less no. of records
        
    $rs_next $row_start $howmany// where would next page start, given current start plus no. of records
     
        // If for some reason the next <prev> starting point is negative, do not display <prev>
        // This happens when our current starting point is already 0
        // This may happen if some smartass manually changes the rs= bit in the url
        
    $page_output_prev     = ($rs_prev 0) ? "" "<div id=\"next\"><a href='?layouts=".$cat."?rs=".$rs_previous."'>Previous</a></div>";
     
        
    // Will the next page jump start point exceed the number of records returned?
        // If so, don't display <next>'
        
    $page_output_next     = ($rs_next >= $count_result) ? "" "<div id=\"next\"><a href='?layouts=".$cat."?rs=".$rs_next."'>Next</a></div>";
     
        
    // Just something to put between <prev> & <next>, IF they are both active
        
    if (($page_output_prev == "") || ($page_output_next == "")) {$page_output_breaker "";}
        else { 
    $page_output_breaker " || ";}
     
        
    // Build final paging output
        
    $page_output $page_output_prev $page_output_breaker $page_output_next;
    }
     
    // Write the outputs
    echo $line_output;
    echo 
    $page_output;
     


        
        include(
    "template/footer.php");
    ?>
    It basically takes the info from the database and paginates it. Each set of data is in a category however the url is like
    Code:
    http://www.mysite.com/layouts.php?layouts=14
    when I would like it to go to the next page it goes to
    Code:
    http://www.mysite.com/layouts.php?layouts=14?rs=4
    and then to
    Code:
    http://www.freetweetgraphics.com/layouts.php?layouts=14?rs=4?rs=4
    etc. etc. all I get is 4 display results (which are the same each time) on each page.

    How do i get it to update to the next 4 peices of data from each category?

  2. #2
    Join Date
    Dec 2006
    Location
    Swindon
    Posts
    3,299
    Tokens
    215
    Habbo
    dunko

    Latest Awards:

    Default

    ?rs=8

    not ?rs=4?rs=4

  3. #3
    Join Date
    Jan 2009
    Location
    UK
    Posts
    42
    Tokens
    0

    Default

    I know that is what needs to be done however I don't know who to make it do that.

    Also I now have another problem now. Say if I added a layout to category 14, 12 and 9 all three layouts will show up in each category.

Posting Permissions

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