Jump to content

Pagination tutorial advice just asking on the offset variable calculation


j.smith1981

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.