Page 1 of 1
Counting up, but with Page Numbering....?
Posted: Wed Apr 27, 2011 12:28 pm
by simonmlewis
Hi
Got a problem that seems so lame, but I cannot fathom how to fix it.
I have a page that displays people's names, and by each name it counts up by 1.
ie.
1 Fred
2 Joe
3 Sally.
But the page produces a few hundreds, so I have page numbering, and when you go to Page 2 (or over), it restarts at one.
This is the simple code I use for the 1, 2, 3....
Code: Select all
$start = $start + 1;
echo "$start";
How do I make each page (there are 7 at the moment) of 40 carry on from the previous $start number?
Re: Counting up, but with Page Numbering....?
Posted: Wed Apr 27, 2011 12:44 pm
by pickle
You want to research "pagination".
Generally this is accomplished with the LIMIT clause of the query.
ie: If you're on page 1, the query would look like:
If you're on page 2:
You generally store the page number in the URL:
http://yourwebsite.com/results/?page=2
Re: Counting up, but with Page Numbering....?
Posted: Wed Apr 27, 2011 12:47 pm
by simonmlewis
Sorry I don't think I made my self terribly clear then.
I don't need page numbering: that is sorted.
I need to count up one by one to show by each person.
Please reading my post again. I don't need page numbers.
Re: Counting up, but with Page Numbering....?
Posted: Wed Apr 27, 2011 1:01 pm
by pickle
Ah, I see.
You can still store the $start in the URL & initialize to 1 if it's not found.
Re: Counting up, but with Page Numbering....?
Posted: Wed Apr 27, 2011 1:53 pm
by McInfo
Basically, the math is
Code: Select all
first_line_number = (page_number - 1) * number_of_lines_per_page + 1
assuming that page numbers start at 1 and line numbers start at 1 on the first page.
Re: Counting up, but with Page Numbering....?
Posted: Thu Apr 28, 2011 3:29 am
by simonmlewis
Bingo.
Code: Select all
if(isset($_GET['start']))
{
$start = $_GET['start'];
}
Before the MySQL query.
Then the SELECT query.
Then after 'WHILE' {...
Code: Select all
$start = $start + 1;
echo "$start";
Just took a bit of working out in which order and placement it had to go. But works great. Thanks.