treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Number of pages?

  • Usually on forum sites such as this one css-tricks. On the bottom it has page 1, 2, 3 etc. it aslo has the next page button and the previous button. My question is how would one do such a thing?
  • Whatever software you use to power your forum -- the pagination is usually taken care of automatically, though you will have to define in the forum settings how many discussions a page will have maximum, and how many posts should a discussion have maximum, before it's divided into pages.
  • IF you are using a "while ($row = mysql_fetch_assoc..." you can easily in the string you are refering to (the one where you pull out the information you list) change the limit according to say "page" from the URL.
    Something like this:

    $limit = $_GET['limit'];
    if (empty($limit)){
    $limit = 10;
    }
    $string = mysql_query("SELECT * FROM forums LIMIT 0, $limit");
    while ($row = mysql_fetch_assoc($string)){
    [...]

    This is how I do it. Then I add a link that's somewhat like this below everything:

    <a href="/forum.php?page=<?php echo($limit + 10); ?>">Display more</a>


    You can of course change the first limit as well to be -10 of what the second one is, making them into "pages".