j.smith1981 Posted October 12, 2011 Share Posted October 12, 2011 Hi there I am having a bit of a trouble understanding what I think this pagination variable means as a literal value, though I know of course it's going to be dynamic but I wanted to make sure I was thinking the right way about this. This is going by this tutorial here: http://www.phpfreaks.com/tutorial/basic-pagination With reference to this part here: // the offset of the list, based on current page $offset = ($currentpage - 1) * $rowsperpage; If I was on page 1 at the moment I would go from 0-9 and see those results right? If I then went to page 2 that would be (would that be 11) deduct 1 and then 10-19? I am getting a bit confused, I think I have it but I mean I just wanted to double check. Any helps much appreciated, Jeremy. Quote Link to comment https://forums.phpfreaks.com/topic/248971-pagination-tutorial-advice-just-asking-on-the-offset-variable-calculation/ Share on other sites More sharing options...
TOA Posted October 12, 2011 Share Posted October 12, 2011 It's where the db starts grabbing rows for that page. You can see on the next line how it's being used $sql = "SELECT id, number FROM numbers LIMIT $offset, $rowsperpage"; Hope that makes sense. Quote Link to comment https://forums.phpfreaks.com/topic/248971-pagination-tutorial-advice-just-asking-on-the-offset-variable-calculation/#findComment-1278615 Share on other sites More sharing options...
j.smith1981 Posted October 12, 2011 Author Share Posted October 12, 2011 Ahh yes I output the SQL and it makes perfect sense. Thank you so much it's just pagination had been bugging me for a good few months and knew I would go back to it at some point, still struggling with a few of the last points but I am getting there. Thank you so much. Jeremy. Quote Link to comment https://forums.phpfreaks.com/topic/248971-pagination-tutorial-advice-just-asking-on-the-offset-variable-calculation/#findComment-1278626 Share on other sites More sharing options...
TOA Posted October 12, 2011 Share Posted October 12, 2011 Ahh yes I output the SQL and it makes perfect sense. Thank you so much it's just pagination had been bugging me for a good few months and knew I would go back to it at some point, still struggling with a few of the last points but I am getting there. Thank you so much. Jeremy. It can be a confusing topic. Glad it helped. Quote Link to comment https://forums.phpfreaks.com/topic/248971-pagination-tutorial-advice-just-asking-on-the-offset-variable-calculation/#findComment-1278627 Share on other sites More sharing options...
j.smith1981 Posted October 13, 2011 Author Share Posted October 13, 2011 Hello I was wondering if it would be alright to ask about this loop please? This loop here (I have changed some of it to show that I am making an effort but struggling to understand it 100%) I hate it when I want to use something but lack a thorough understanding of a little snippet of code, here's it and my assumptions below: <?php for($i = ($current_page - $show_links); $i < (($current_page + $show_links) + 1); $i++) // this bit I am struggling with, the condition for the loop only! { // if it's a valid page number! if(($i > 0) && ($i <= $total_pages)) { } } The bit I don't get is say I was on my 4th page out of 25 total pages right? (just for arguements sake) I then have 5 links shown at any time, so -4 as my value in the brackets right? I don't get what would happen if that was to occur, that's my problem can someone help me to understand this better what's actually really going on with this logic please? Thanks ever so much in advance, Jeremy. Quote Link to comment https://forums.phpfreaks.com/topic/248971-pagination-tutorial-advice-just-asking-on-the-offset-variable-calculation/#findComment-1278969 Share on other sites More sharing options...
TOA Posted October 13, 2011 Share Posted October 13, 2011 Not really sure what you're asking for. Quote Link to comment https://forums.phpfreaks.com/topic/248971-pagination-tutorial-advice-just-asking-on-the-offset-variable-calculation/#findComment-1279006 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.