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 9 of 9

Thread: Pagination

  1. #1
    New Coder
    Join Date
    Apr 2009
    Location
    UK
    Posts
    56
    Thanks
    5
    Thanked 1 Time in 1 Post

    Pagination

    Hello,

    I have an image hosting script with an admin backend - but all images just show on one page - i can't find a pagination script to get it to work! Also, when a new file is uploaded, it appears at the bottom of the page - can someone work out how to get it to appear at the top?

    Could someone tell me how to do this please?

    PHP Code:
    <title>planetK Moderation</title><font face='verdana'> <?
    session_start
    ();
    if(!
    session_is_registered(myusername)){
    header("location:admin.php");
    }
    ?>
    <?
    include("config.php");
     function 
    getExtension($str) {
             
    $i strrpos($str,".");
             if (!
    $i) { return ""; }
             
    $l strlen($str) - $i;
             
    $ext substr($str,$i+1,$l);
             return 
    $ext;
     }
    echo 
    "<center><br><font face=verdana size=4><b>picK Image Moderation</b></font></center>";
    echo 
    "<p align=center><font size=1 face=verdana><a href=admin_success.php>Moderation</a>| <a href=admin_success.php?p=u>Ban List</a> | <a href=admin_logout.php>Logout</a></font></p><br>";

    $con mysql_connect($data_server$data_user$data_pw)
                    or die(
    "<font color= red>Couldn't connect to Database. Try again.</font>");
                    
    mysql_select_db("db");
    if(
    $_GET['p'] == ""){
    $result mysql_query("SELECT * FROM image_table "
    or die(
    mysql_error());  
    print 
    "<font face='verdana' size='1'><center><table border=1px #000000 solid><tr><td>File Preview</td><td>Delete</td><td>Ban</td></tr>";
    while(
    $row mysql_fetch_array$result )) {
    $filename $row['image'];
    $extension getExtension($filename);
    $extension strtolower($extension);
    if(
    $row['image'] == ""){
    } else {
    if(
    $extension == "jpeg" || $extension == "jpg" || $extension == "png" || $extension == "gif" || $extension == "bmp") {
    //Echo Link
    echo "<tr><td><a href='";
    echo 
    $row['image'];
    echo 
    "' border='0'>";
    echo 
    "<img src='";
    echo 
    $row['image'];
    echo 
    "' width='70px' height='70px' border='0'></a></td><td>";
    } else {
    //IF NOT AN IMAGE
    //CLICK HERE LINK
    echo "<font face=verdana size=small>";
    echo 
    "<tr><td><a href='";
    echo 
    $row['image'];
    echo 
    "'>Click here</a></td><td>";
    }
    //DELTE
    echo "<a href='deleted.php?name=";
    echo 
    $row['image'];
    echo 
    "'>Delete File</a></td><td>";
    //BAN
    echo "<a href='banban.php?ip=";
    echo 
    $row['ip'];
    echo 
    "'>Ban</a>";
    echo 
    "<br />";
    echo 
    $row['ip'];
    echo 
    "</font>";
    echo 
    "</td></tr>";

    }
    }
    if(
    $_GET['p'] == "u"){
    mysql_connect($data_server$data_user$data_pw)
                    or die(
    "Couldn't connect to Database. Try again.");
                    
    mysql_select_db("db");
    $result mysql_query("SELECT * FROM banip "
    or die(
    mysql_error());  
    print 
    "<center><table border='1'>";
    while(
    $row mysql_fetch_array$result )) {
    print 
    "<tr><td>";
    print 
    $row['IP'];
    print 
    "</td><td>";
    print 
    "<a href='unbanban.php?ip=";
    print 
    $row['IP'];
    print 
    "'>Unban IP</a></td></tr>";
    }     
    }
    ?></font>
    I'm still learning :P

    Cheers,
    James
    Last edited by jamesk; 02-16-2010 at 01:32 PM. Reason: removing db name

  • #2
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    http://www.jaygilford.com/php/comple...ination-class/
    Instructions are on the site on how to integrate it with your code

    Any problems post back

    Jay
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • Users who have thanked JAY6390 for this post:

    jamesk (02-16-2010)

  • #3
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    OK download the class into the same directory as this script (naming it paginate.class.php), then change your script to the following and hopefully it will work
    PHP Code:
    <title>planetK Moderation</title><font face='verdana'> <?
    require 'paginate.class.php';
    $page = isset($_GET['page']) ? $_GET['page'] : 1;
    session_start();
    if (!
    session_is_registered(myusername)) {
        
    header("location:admin.php");
    }

    include (
    "config.php");
    function 
    getExtension($str)
    {
        
    $i strrpos($str".");
        if (!
    $i) {
            return 
    "";
        }
        
    $l strlen($str) - $i;
        
    $ext substr($str$i 1$l);
        return 
    $ext;
    }
    echo 
    "<center><br><font face=verdana size=4><b>picK Image Moderation</b></font></center>";
    echo 
    "<p align=center><font size=1 face=verdana><a href=admin_success.php>Moderation</a>| <a href=admin_success.php?p=u>Ban List</a> | <a href=admin_logout.php>Logout</a></font></p><br>";

    $con mysql_connect($data_server$data_user$data_pw) or die("<font color= red>Couldn't connect to Database. Try again.</font>");
    mysql_select_db("db");
    if (
    $_GET['p'] == "") {
        
    // Query to run
        
    $query "SELECT * FROM image_table ";
        
        
    // Load paginator
        
    $paginator = new pagination($page$query);
        
        
    // Number of results on each page
        
    $paginator->results_per_page 10;
        
        
    // Number of pages to show around current page number in links
        
    $paginator->padding(2);
        
        
    // Link prefix before page number
        
    $paginator->link_prefix '?page=';
        
        
    // Paginate the results
        
    $page_links $paginator->paginate();
        
        
    // Echo out the page links
        
    echo $page_links;
        
        print 
    "<font face='verdana' size='1'><center><table border=1px #000000 solid><tr><td>File Preview</td><td>Delete</td><td>Ban</td></tr>";
        while (
    $row mysql_fetch_array($paginator->resource())) {
            
    $filename $row['image'];
            
    $extension getExtension($filename);
            
    $extension strtolower($extension);
            if (
    $row['image'] == "") {
            } else {
                if (
    $extension == "jpeg" || $extension == "jpg" || $extension == "png" || $extension ==
                    
    "gif" || $extension == "bmp") {
                    
    //Echo Link
                    
    echo "<tr><td><a href='";
                    echo 
    $row['image'];
                    echo 
    "' border='0'>";
                    echo 
    "<img src='";
                    echo 
    $row['image'];
                    echo 
    "' width='70px' height='70px' border='0'></a></td><td>";
                } else {
                    
    //IF NOT AN IMAGE
                    //CLICK HERE LINK
                    
    echo "<font face=verdana size=small>";
                    echo 
    "<tr><td><a href='";
                    echo 
    $row['image'];
                    echo 
    "'>Click here</a></td><td>";
                }
                
    //DELTE
                
    echo "<a href='deleted.php?name=";
                echo 
    $row['image'];
                echo 
    "'>Delete File</a></td><td>";
                
    //BAN
                
    echo "<a href='banban.php?ip=";
                echo 
    $row['ip'];
                echo 
    "'>Ban</a>";
                echo 
    "<br />";
                echo 
    $row['ip'];
                echo 
    "</font>";
                echo 
    "</td></tr>";
            }
        }
    }
    if (
    $_GET['p'] == "u") {
        
    mysql_connect($data_server$data_user$data_pw) or die("Couldn't connect to Database. Try again.");
        
    mysql_select_db("db");
        
    $result mysql_query("SELECT * FROM banip ") or die(mysql_error());
        print 
    "<center><table border='1'>";
        while (
    $row mysql_fetch_array($result)) {
            print 
    "<tr><td>";
            print 
    $row['IP'];
            print 
    "</td><td>";
            print 
    "<a href='unbanban.php?ip=";
            print 
    $row['IP'];
            print 
    "'>Unban IP</a></td></tr>";
        }
    }
    ?></font>
    Note your code is very poor (ie written in tables and <font> tags). You should consider upgrading it to a higher standard tbh.
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #4
    New Coder
    Join Date
    Apr 2009
    Location
    UK
    Posts
    56
    Thanks
    5
    Thanked 1 Time in 1 Post
    I will be changing the page to css and div tags - i hate tables - but it'll do for now...

    As I said, I'm just happy this script is actually working - uploading images lol

    Edit; This is what I get:

    Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /home/j/k/jkealey/public_html/pick/paginate.class.php on line 17

  • #5
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    Not sure why you get that. The pagination script has no errors. Did you modify it in any way? Make sure you download the pagination script instead of copy pasting it off the site to be absolutely sure. it should show a download box when you click the download button
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #6
    New Coder
    Join Date
    Apr 2009
    Location
    UK
    Posts
    56
    Thanks
    5
    Thanked 1 Time in 1 Post
    I did, I downloaded it straight off and put it in the same directory as the other page. I then copied and pasted the script from above and replaced the page.

    Looks like the error is with your script... :S

    James

  • #7
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    can you create a temp ftp user and pass and PM me the details of your site so that I can see what it might be. both scripts have no errors according to my php parser
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #8
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    As I expected my pagination class is fine, as was the code I gave you to run. The problem was your servers version of PHP (Version 4.4.1). The pagination script is for version 5 and above of PHP. PHP 4 was deprecated as of December 31st 2007 so its assumed all hosting now has PHP5 (although since you are on a free host you can't really do anything about it). I've changed the script so that all the public and private keywords are removed, and added a pagination function to the class since __construct won't work. It now works (I changed the results per page to 1 to demonstrate since you only have 3 items to paginate)
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #9
    New Coder
    Join Date
    Apr 2009
    Location
    UK
    Posts
    56
    Thanks
    5
    Thanked 1 Time in 1 Post
    Oh right, Cheers


  •  

    Posting Permissions

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