Jump to content

Need help figuring out values that I need


Go to solution Solved by jcbones,

Recommended Posts

Basically, with the project that I have going now I am using $pageNumber to indicate what page that the user is currently on. I want to display 10 articles for each page for example:

 

$pageNumber == 1 >> $start=1; $stop=10;

$pageNumber == 2 >> $start=11, $stop=20;

$pageNumber == 3 >> $start=21, $stop=30;

$pageNumber == 4 >> $start=31, $stop=40;

etc..etc..

 

However, I have not the slightest idea on how to go about this. Could someone get me pointed in the right direction? There will eventually be quite a number of pages and typing all of them out manually would take a long time.

Edited by NalaTheFurious

Deleted my response. I'm pretty sure this is homework and the problem is super easy. At least show an attempt at what you've tried - then ask for help showing what you tried.

 

That's kind of rude.. not everyone is trying to do homework. I'm actually trying to make my website operational while studying for other courses though. The only thing that came to mind for me was setting the values manually for each page and that was clearly not the approach to use, but I did it anyways for the first coulpe of pages to test. I have been wrapping my mind around how to do this and nothing has been coming to mind. I have a bunch of other php incoperated into my website and some of it is highly advanced.. it's just something so simple is causing me a headache.

Perhaps you've already done this, but you could search for "php pagination" on a search engine like Google.

 

I couldn't quite find what I was looking for when I searched for this.

 

 

We still need to see code. We have no idea where the articles are coming from.

 

There blogs are collected like such:

$blogs = BlogRange($start, $stop);

BlogRange selects blogs based off id between two numbers.. $start and $stop in this case. However, to get the $start and $stop numbers correct. Reffering to my original post I am trying to set $start and $stop based off the page number the user is currently on.. example: http//website.com/page/1 which in the code is $pageNumber

 

When the $pageNumber is 1 I need the $start value to be 1 and $stop to be 10.

When the $pageNumber is 2 I need the $start value to be 11 and $stop to be 20.

etc.

etc.

And you still haven't told us where the articles are coming from. I guess you don't want help after all.

 

Why are you acting so condescending? I answered your question previously.. the articles are stored in $blog from a call such as

$blogs = BlogRange($start, $stop);

Where the articles come from is not really the issue here.. that works just fine for me. I am just trying to figure out a way to check my $pageNumber and get the corresponding range of values to pull from the database.

 

------

$pageNumber = 1;

$start = 1;

$stop = 10;

------

------

$pageNumber = 2;

$start = 11;

$stop = 20;

------

etc..etc..

 

That way when a person is on my website viewing page 60 $pageNumber will equal 60 and I am trying to figure out a way to calcuate the $start and $stop based off the page number. However, typing it all out manually for each page would take forever.. just trying to write a function where I can input the $pageNumber and get the range of numbers I need for my $start and $stop.

Edited by NalaTheFurious

Why are you acting so condescending? I answered your question previously.. the articles are stored in $blog from a call such as

 

Because if the data comes from a database the technique used for paginating your data will be different from that used if it comes from a text or xml file.

So:

$pageNumber = (int)$_GET['page'];
$stop = $pageNumber * 10;
$start = $stop - 9;

??

 

That's exactly what I needed.. thank you. I just couldn't think of this or how to describe this to save the life of me.

 

 

Because if the data comes from a database the technique used for paginating your data will be different from that used if it comes from a text or xml file.

 

I was trying to explain though that none of that matters because I knew the answer was much simplier than what you wanted to know.

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.