SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Member
    Join Date
    Jul 2009
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Pagination problems

    Hi, I am new at PHP. I need to make a pagination on my site and here's a code that seems to be working but when I go into different pages I get a message that says "page not found". Can someone please help me with this. Thanks.

    PHP Code:
    <?php
    $username
    ="pass";
    $password="pass";
    $database="mysql";

    $dbh=mysql_connect(localhost,$username,$password) or die ('I cannot connect to the database because: ' mysql_error());
    @
    mysql_select_db($database);


    $result mysql_query("SELECT COUNT(*) AS total_entries FROM help_topic") or die(mysql_error());
    $row mysql_fetch_row($result);


    $total_entries $row[0];



    $entries_per_page 25;


    if(isset(
    $_GET['currentpage'])) {
    $page_number $_GET['currentpage'];
    } else {
    $page_number 1;
    }



    $total_pages ceil($total_entries $entries_per_page);


    $offset = ($page_number 1) * $entries_per_page;


    $result mysql_query("SELECT * FROM help_topic LIMIT $offset$entries_per_page") or die(mysql_error());
    while(
    $obj mysql_fetch_array($result)) {
    // Display the data however you want here.
    print $obj ['url'];
    echo 
    "<br>";
    }


    for(
    $i 1$i <= $total_pages$i++) {
    if(
    $i == $page_number) {
    // This is the current page. Don't make it a link.
    print "$i ";
    }else {
    // This is not the current page. Make it a link.
    print "<a href=\"untitled.php?page_number=$i\">$i</a> ";

    }
    ?>

    I really appreciate your help...

  2. #2
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Can you give us an example URL that it sends you to when you click the link?

    Are you sure untitled.php is the file you're working on? Maybe you need to change that.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  3. #3
    SitePoint Member
    Join Date
    Jul 2009
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you. I am trying bu the system would not allow me to post urls. Any suggestions.
    Here's the page that shows up on browser which is good:
    Untitled-1.php but when I go to another page, I get this:
    untitled.php?page_number=2 with this error:
    Not Found

    The requested URL /websites/sun/untitled.php was not found on this server.

    I really need to get this done ASAP. I am under a time frame to finish this site. Thaks again.


    I keep getting this:

    We noticed that your post contains a link.

    We'd really love to let you publish it, but unfortunately you don't yet have enough posts under your belt. Consider it a way of "earning your stripes".

    It's silly, we know, but we've had to resort to these measures to combat all of the nasty spam that has been hitting our site lately. Sorry about that-we really value what you have to say, so feel free to remove your link from the text field below, and try again.

    Thanks for your understanding. Oh, and if you ever meet one of those spammers, throw a tomato at them for me, will you?

    Have a great day!
    Team SitePoint

  4. #4
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    That's understandable, I didn't see your post count.

    Well, think about what the URL SHOULD be for the second page, and what it is when you click the link. Then look again at your code, especially the bottom - that's what is making the URL what it is.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  5. #5
    SitePoint Member
    Join Date
    Jul 2009
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by arkinstall View Post
    Can you give us an example URL that it sends you to when you click the link?

    Are you sure untitled.php is the file you're working on? Maybe you need to change that.
    OK, I got your tip, I changed to the page I'm working on which is untitled-1.php and it's going from page to page without errors but the only problem now is that, although its changing, it's not changing the information. Any suggestions? Thanks

  6. #6
    SitePoint Member
    Join Date
    Jul 2009
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Any suggestions guys? I really need to finish this site. thanks

  7. #7
    SitePoint Enthusiast
    Join Date
    Feb 2009
    Location
    Lexington, KY
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you print out your $offset to make sure it's changing?

  8. #8
    messing with my mind fristi's Avatar
    Join Date
    Feb 2009
    Posts
    292
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    edit: sorry I didn't see the next post, so I deleted all of my useless explanation.

    Seems I can't just delete a post :/
    To PHP or to Perl, that is the question!
    (Bucket - simpletest) User

  9. #9
    SitePoint Member
    Join Date
    Jul 2009
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by mattcaldwell View Post
    Can you print out your $offset to make sure it's changing?
    How do I do that Matt? At this point I'll try anything. Thanks

  10. #10
    SitePoint Enthusiast
    Join Date
    Feb 2009
    Location
    Lexington, KY
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Could you just do a: print 'offset='.$offset; ? Right underneath the line where you set $offset.

  11. #11
    SitePoint Member
    Join Date
    Jul 2009
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks I got it working...


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
  •