Log in

View Full Version : 1,2,3,4,5 etc next page 6,7,8,9,10 and so on



shyne
07-29-2007, 01:18 AM
Hi

I want3d to know how do I achieve this.

I have a php pagination and it shows everything fine and works nicely but it is missing one thing and that is the feature to continue from last number of previous page. lets say my page shows 10 users and it gives a number before each name like below:

1: John
2: Michael
3: Shafiq
4: Hedar
5: Josh

and then you click on page 2 and it should start from 6,7,8,9,10 but instead it counts back from 1,2,3,4,5. If someone could help me out here. Thats would be nice. Here is the pagination script.


$entries_per_page = "5";
if(isset($_GET['page'])) {
$page = $_GET['page'];
} else {
$page = 1;
}
$total_pages = ceil($count / $entries_per_page);
$offset = ($page - 1) * $entries_per_page;
$i = -1;

for($i = 1; $i <= $total_pages; $i++) {
echo "<a href=\"page$i\">$i</a> - ";
}

$qphoto = "SELECT * FROM `jhjkhjk` WHERE ft_id = '$ft_id' ORDER BY `pic_id` DESC LIMIT $offset, $entries_per_page";
$rphoto = mysql_query($qphoto);
$w = 0;
if (!$rphoto){
die ("Could not query the database:<br />Houston! we have a problem here. ". mysql_error());
}
while ($p = mysql_fetch_array($rphoto, MYSQL_ASSOC)) {
$w++;

echo "$w: $p[name]";

}


The above code is juss snippet of my code. If any of you have any custom pagination that would do what I am trying to achieve then please let me know.

Thanks alot.

mburt
07-30-2007, 02:42 PM
Use simple math: Depending on what the page value increment is, add the according value to your numbers.

For example, say if $_GET["page"] is 0 then 5, 10 and so on.

($i+($_GET["page"]))

shyne
07-30-2007, 06:32 PM
Hi
thanks for the reply

Can you please tell me where do I put the code in? lol sorrie but I just coudn't figure it out.

djr33
07-30-2007, 07:02 PM
http://www.php-mysql-tutorial.com/php-mysql-paging.php

Everything you need to know should be there.

shyne
07-31-2007, 03:43 AM
Thanks alot I luv dat tutorial. I actually changed it to that but I still am struggling with my above problem. If some one could show where to put the code in to make et work. That wud b nice.

Thanks

tech_support
07-31-2007, 05:51 AM
Slang: U ned to put it where u want 2 page stf.

Proper: You need to put it where you want to put the pagination stuff.

shyne
08-01-2007, 07:25 PM
OK LOL

But you guys are not getting what I am saying here. I need to know how can I make the numbered list in the pagination to continue from where it left off on the previous page. Lets say I have 5 users in the first page and they start off like this:
1. Michael
2. John
3. Ali
4. Mushi
5. Heather

And then page 2 it should start like this:

6. Henry
7. Tom
8. Kim
9. Sara
10. Kelly

But now I don't know what code to put where in my pagination code. Thats what I am asking if someone could tell me where to put what to make it work, since the second page starts back from 1 instead of continuing from where the last result was previous page.

Thanks

tech_support
08-02-2007, 06:45 AM
Where are you getting this from?

shyne
08-02-2007, 04:56 PM
Where are you getting this from?

If I got your question correctly then I am getting it from MYSQL database using PHP, but if you question was asking me something else then I didn't get your question.

tech_support
08-03-2007, 09:41 AM
Ah. How are your tables sorted? You'll need to setup your SQL line with LIMIT 10 etc.

As djr33 linked before, here's (http://www.php-mysql-tutorial.com/php-mysql-paging.php) a good tutorial on how to do it.

shyne
08-03-2007, 11:22 PM
I did bro. I have everything working as I said. The pagination works fine. The only thing that I want to see added to my pagination is the ability to have the numbers countinue from where it left off previuos page, just like I said in my example.

Page 1 shows the below:
1. John
2. Micdhela
3. HHhjaja
4. Jajkhakj
5. Uhajma

The page 2 shows the below:
1. Laila
2. JjkKjka
3. Blah Blah
4. Bljaa
5. IIloa whatever

Now if you see the numbers in BOLD you will notice how on page 2 it starts back from 1 instead of starting from 6, thats what I want toi include in my pagination, so that the count starts from where it left off on previous page. It shouldn't be this hard to get what I am saying :"(

tech_support
08-04-2007, 12:26 AM
Obviously. It's cause you started the counter at 0 :p
Try replacing this:


$w = 0;

with this:


$wheretostart = (integer) $_GET['page'];
$wheretostart = $wheretostart*5;
$w = isset($_GET['page']) ? $wheretostart : 0;

shyne
08-07-2007, 07:17 PM
Hi Thanks you for the code.
BUT it starts the count from 11 on page 2 instead of 6. And when I click back on page 1 it starts the count from 6 instead of 1. I think there is just a lil bit more to be added to your code:) I am waiting

Thanks buddy.

tech_support
08-08-2007, 06:27 AM
Oops. Multiplied instead of plus.


$wheretostart = (integer) $_GET['page'];
$wheretostart = $wheretostart+5;
$w = isset($_GET['page']) ? $wheretostart : 0;

shyne
08-08-2007, 06:45 AM
lol sorry but it still is not working properly.
You see it starts fine but when you click on page 2 it starts from 8 and then page 3 it starts from 9. And then when you click on page 1 again it starts from 7.

tech_support
08-08-2007, 06:50 AM
Do some random math operations. Aim at this line:

$wheretostart = $wheretostart+5;
while I think of something.

shyne
08-08-2007, 06:16 PM
What I found out is that putting a Multiply * instead of plus + makes it work better.

When I tried putting a + it just messes up the count totally, it starts count at 7 for first page, 8 for second page and 9 for third page.
BUT
When I put * it starts the count from 11 on page 2 instead of 6, it seems like its starting the count from 5 instead of 1, and thats the only thing that needs to fixed, somehow for the count to start from 1

tech_support
08-09-2007, 06:49 AM
$wheretostart = (integer) $_GET['page'];
$wheretostart = $wheretostart*5;
$w = isset($_GET['page']) ? $wheretostart : 0;
if ($wheretostart==1) { $w=0; }

shyne
08-09-2007, 06:46 PM
NO LICK again here.

Its the same thing. It starts from 11 on page 2 and when clicked back to page 1 it starts from 6. :(

shachi
08-10-2007, 09:04 AM
Ok, here's the simple algorithm:



get the page number from the URL(e.g ?pg=2)
multiply that number by the number of results you want(if ten, then, 10*2 = 20) which will be your starting point
in your select add something like "SELECT * FROM yourtable LIMIT startindex-1, number of results"

tech_support
08-11-2007, 05:22 AM
NO LICK again here.

Its the same thing. It starts from 11 on page 2 and when clicked back to page 1 it starts from 6. :(
Ok... how are you getting the page number. ?page=[PAGE NUMBER] ?

shyne
08-13-2007, 12:30 AM
I am getting the page numbers like this:
index.html?page_id=14&cat_id=2&page=2

tech_support
08-13-2007, 09:37 AM
Can we have your full code please?