PHP Pagination Question(s).

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Publisher Bucks
    Confirmed User
    • Oct 2018
    • 1330

    #1

    Tech PHP Pagination Question(s).

    So this week my goal is to setup pagination on my recipe site but, before I dive in I was hoping to get some feedback.

    I've been researching a few different options, mainly whether I should begin with recipes.php?page=0 or recipes.php?page=1 as the first page, does either option matter significantly?

    I have read in a few places then when dealing with potentially hundreds of pages, using OFFSET can cause issue?

    Secondly, I'm thinking of using this for the main code snippet:

    $page_number = mysqli_escape_string($con, $_GET['page']);
    $count_per_page = 20;
    $next_offset = $page_number * $count_per_page;
    $cat =mysqli_query($con, "SELECT * FROM Recipes LIMIT $count_per_page OFFSET $next_offset");
    while ($row = mysqli_fetch_array($cat))
    $count = $row[0];
    Is that the simplest way of achieving what I need to happen (main results page, with navigation to X amount of other pages) or will the OFFSET stuff cause issue because the items on the page is low thus generating hundreds of pages?

    Also, is that TOO simple and restrictive as far as the functions go of generating the page navigation?

    Finally, when it comes to the navigation itself, is it best (in your experience) to just have numerical pages listed or should I also include a 'PREVIOUS' and 'NEXT' link on the navigation structure?

    Thanks in advance for any advice and feedback you can offer
    Extreme Link List - v1.0
  • ZTT
    Confirmed User
    • Apr 2019
    • 659

    #2
    Unfortunately nobody can really answer your questions as well as you can yourself, because nobody but you knows what you want to achieve.

    Personally I would never use pagination even if the fate of the world depended on it, but then I also wouldn't use a database or PHP when it can be avoided, and I have no idea why you're trying to code everything from the back end to the front end yourself when there are plenty of recipe templates and themes already out there.

    I think it would actually be less of a chore, and would provide a far better, more interesting/personalized experience for visitors, to simply write a blog on Wordpress.com, adding 10 recipes per day, at least if there's some genuine enthusiasm and knowledge about the subject, than grinding away on what seems to be just another recipe dump like hundreds of others that already exist.

    To specifically address your questions:

    "whether I should begin with recipes.php?page=0 or recipes.php?page=1 as the first page, does either option matter significantly?"
    Machines typically count from 0; humans from 1. That's it. Just use whatever works in your code, because no internet user, including you, has ever cared whether a URL has a 0 or 1.

    "I have read in a few places then when dealing with potentially hundreds of pages, using OFFSET can cause issue?"
    Why would you even have hundreds of pages? It's a scientific fact that no human in their right mind (who wasn't stealing/scraping content) has ever clicked further than page 5 of anything.

    "when it comes to the navigation itself, is it best (in your experience) to just have numerical pages listed or should I also include a 'PREVIOUS' and 'NEXT' link on the navigation structure?"
    Pagination is always the worst solution - almost nobody reads past page one anyway, and nobody at all cares about more than 100 items of anything, so even if you don't want to lazy load, just put 100 results on one page and let people find other stuff in other ways, such as categories or 'related' suggestions.

    If you absolutely must use the worst, most tedious navigation method ever, you can again answer your own question - is it nicer when there's a big PREVIOUS and NEXT button to click, or is it better when you have to exactly hit an 8x8 pixel arrow or number?

    You're a user too; if you think something makes things easier, do it, and if you think it makes things harder, don't do it. Certainly never let 'style', which is subjective anyway, override user experience.
    __________________

    Comment

    • Publisher Bucks
      Confirmed User
      • Oct 2018
      • 1330

      #3
      Unfortunately nobody can really answer your questions as well as you can yourself, because nobody but you knows what you want to achieve.
      I'm sure that several people have advice on whether certain functions, features and methods can put a strain on a server based on their own experiences or what can or can't make a site load slower based on those same functions, features and methodologies.

      I have no idea why you're trying to code everything from the back end to the front end yourself when there are plenty of recipe templates and themes already out there.
      Because I'm teaching myself to code using .php, sure there are thousands of Wordpress templates and themes out there but if I use one of those, I'll not learn anything about coding.

      Machines typically count from 0; humans from 1. That's it. Just use whatever works in your code, because no internet user, including you, has ever cared whether a URL has a 0 or 1.
      Unless it comes to placing extra server strain/load resulting in negative load times due to having to recount pagination functions each and every time a web page loads.

      Why would you even have hundreds of pages? It's a scientific fact that no human in their right mind (who wasn't stealing/scraping content) has ever clicked further than page 5 of anything.
      Because having hundreds of pages is a good way to get niche specific traffic to a recipe site directly from the search engines, being able to filter results based on ingredient, recipe type or cooking method is going to generate hundreds of pages and in theory will attract a larger source of organic traffic over time.

      Based on your opinion, no website anywhere should ever have more than 5 pages. There go all the TGPs, Link Lists, Directories, Review Sites and Pay Site Tours with previews, even GFY has a lot more than 5 pages listed on their page navigation for the forum.

      Pagination is always the worst solution - almost nobody reads past page one anyway, and nobody at all cares about more than 100 items of anything, so even if you don't want to lazy load, just put 100 results on one page and let people find other stuff in other ways, such as categories or 'related' suggestions.
      As mentioned, its not just about the end-user experience, but also for the search engines.

      You're a user too; if you think something makes things easier, do it, and if you think it makes things harder, don't do it. Certainly never let 'style', which is subjective anyway, override user experience.
      I'm also a site owner and while user experience is a large part of owning a website, profitability, design, functionality and layout in addition to style are all important aspects of owning a website.

      I appreciate your opinions though and will definitely take them into account, thank you
      Extreme Link List - v1.0

      Comment

      • fuzebox
        making it rain
        • Oct 2003
        • 22351

        #4
        Jesus dude, take this to stackoverflow or something.

        Comment

        • ZTT
          Confirmed User
          • Apr 2019
          • 659

          #5
          Originally posted by Publisher Bucks
          I'm sure that several people have advice on whether certain functions, features and methods can put a strain on a server based on their own experiences or what can or can't make a site load slower based on those same functions, features and methodologies.

          Unless it comes to placing extra server strain/load resulting in negative load times due to having to recount pagination functions each and every time a web page loads.
          This is the point: you're not asking about a problem you have, you're asking about a problem that doesn't exist, and may never exist. Pagination has been used for 20 years, on 20 year old hardware with 20 year old software and code, so why are you worrying so much that it will take down your 2021 server?

          The best way to find out is to simply try it and see if there are issues or not. Worrying about it in advance is just a waste of time and energy.

          BTW, your answer as to why you're coding it all is a good one. Good luck.
          __________________

          Comment

          • plsureking
            bored
            • Aug 2003
            • 4904

            #6
            with pagination, what i like to do is email the visitor the current page, then ask them to enter it on a special form at the bottom of the page. once submitted, i like to shoot a support request over to my ISP and ask them to turn the page.



            #
            Last edited by plsureking; 09-26-2021, 05:22 PM. Reason: typo
            PornCMS / low cost paysite management with hosting

            Comment

            • brassmonkey
              Pay It Forward
              • Sep 2005
              • 77396

              #7
              is it wp pr a php script?
              TRUMP 2026 KEKAW!!! - The Laken Riley Act Is Law!
              DACA ENDED - SUPPORT AZ HCR 2060 52R - email: brassballz-at-techie.com

              Comment

              • zijlstravideo
                Confirmed User
                • Sep 2013
                • 806

                #8
                Originally posted by plsureking
                with pagination, what i like to do is email the visitor the current page, then ask them to enter it on a special form at the bottom of the page. once submitted, i like to shoot a support request over to my ISP and ask them to turn the page.



                #
                Don't forget the sms verification to verify the request first...


                OP's website should have a "Proudly powered by GFY" statement in the footer by now.
                Contact: email

                Comment

                • Klen
                  • Aug 2006
                  • 32235

                  #9
                  Originally posted by fuzebox
                  Jesus dude, take this to stackoverflow or something.
                  Stackoverflow is evil

                  Comment

                  • plsureking
                    bored
                    • Aug 2003
                    • 4904

                    #10
                    Originally posted by zijlstravideo
                    Don't forget the sms verification to verify the request first...


                    OP's website should have a "Proudly powered by GFY" statement in the footer by now.
                    i gotta update my script

                    #
                    PornCMS / low cost paysite management with hosting

                    Comment

                    • brassmonkey
                      Pay It Forward
                      • Sep 2005
                      • 77396

                      #11
                      Originally posted by Klen
                      Stackoverflow is evil
                      a guy actually fixed a error in my script there
                      TRUMP 2026 KEKAW!!! - The Laken Riley Act Is Law!
                      DACA ENDED - SUPPORT AZ HCR 2060 52R - email: brassballz-at-techie.com

                      Comment

                      Working...