Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-28-2012, 03:53 AM   PM User | #16
mfoland
New Coder

 
Join Date: Dec 2010
Posts: 28
Thanks: 4
Thanked 0 Times in 0 Posts
mfoland is an unknown quantity at this point
I got it figured out.. but My start = 0 should be showing 1-20 on the pagination but it's showing 1-21.. Very interesting!
mfoland is offline   Reply With Quote
Old 11-28-2012, 03:55 AM   PM User | #17
KULP
Regular Coder

 
Join Date: Mar 2012
Posts: 166
Thanks: 5
Thanked 11 Times in 11 Posts
KULP is an unknown quantity at this point
Added the compatibility with url.

PHP Code:
<?php
$cnt
100//set to value in database
if(isset($_GET['page']))
    
$currentpage $_GET['page'];
else
    
$currentpage 1// Whatever you wanna use.
$current 1;
$limit 20//Or set to other value, or user defined.

while($current <= $cnt)
{
    
$thislast $current $limit;
    
$url "?page=" $currentpage;
    if(
$thislast $cnt)
    {
          
$thislast $cnt;
    }
    if(
$current == ((($currentpage 1) * 20) + 1))
    {
        echo 
'<p class = "paginationBold">'.  $current ' - ' $thislast '</p>';
    }
    else
    {
        echo 
'<a class = "paginationLink" href = "http://localhost/testing.php?page=' . ((int)($current 20) + 1) . '">' .  $current ' - ' $thislast '</a>' ;
    }
        
$current += $limit//Added this to update $current. Was missing.
}
?>
Quote:
Originally Posted by mfoland View Post
I got it figured out.. but My start = 0 should be showing 1-20 on the pagination but it's showing 1-21.. Very interesting!
1 + 20 = 21

But you can easy fix that.

Last edited by KULP; 11-28-2012 at 05:33 AM..
KULP is offline   Reply With Quote
Old 11-28-2012, 04:02 AM   PM User | #18
mfoland
New Coder

 
Join Date: Dec 2010
Posts: 28
Thanks: 4
Thanked 0 Times in 0 Posts
mfoland is an unknown quantity at this point
Right.. My start is 0 because in my script above in the beginning if the start is 0 it'll show 1-20
mfoland is offline   Reply With Quote
Old 11-28-2012, 04:08 AM   PM User | #19
mfoland
New Coder

 
Join Date: Dec 2010
Posts: 28
Thanks: 4
Thanked 0 Times in 0 Posts
mfoland is an unknown quantity at this point
Also, I went to another page, and my first link for the 0-20 disappeared. hmm

Edit.. nevermind on that. Was experiencing with the $current value! Still figuring out how to make it say 1-20 if i'm on start.. it does goes start = 2. I need them to be by 20..

Last edited by mfoland; 11-28-2012 at 04:11 AM..
mfoland is offline   Reply With Quote
Old 11-28-2012, 04:46 AM   PM User | #20
KULP
Regular Coder

 
Join Date: Mar 2012
Posts: 166
Thanks: 5
Thanked 11 Times in 11 Posts
KULP is an unknown quantity at this point
Try changing

Code:
$thislast = $current + $limit;
to

Code:
$thislast = $current + $limit - 1;
KULP is offline   Reply With Quote
Users who have thanked KULP for this post:
mfoland (11-28-2012)
Old 11-28-2012, 05:00 AM   PM User | #21
mfoland
New Coder

 
Join Date: Dec 2010
Posts: 28
Thanks: 4
Thanked 0 Times in 0 Posts
mfoland is an unknown quantity at this point
That worked.. I'm learning.. Thanks!

Now when I click the link instead of it going by one.. I need it to still go by 20.. My start needs to be 0 for the 1-20 records to show.. So 0 + 20 obviously but then to show the next record.. that's the hard part.. I do want to think it has to do with the link area.
mfoland is offline   Reply With Quote
Old 11-28-2012, 05:02 AM   PM User | #22
KULP
Regular Coder

 
Join Date: Mar 2012
Posts: 166
Thanks: 5
Thanked 11 Times in 11 Posts
KULP is an unknown quantity at this point
Quote:
Originally Posted by mfoland View Post
Now when I click the link instead of it going by one.. I need it to still go by 20..
What? And sorry but I'm not going to code your entire site...
KULP is offline   Reply With Quote
Old 11-28-2012, 05:03 AM   PM User | #23
mfoland
New Coder

 
Join Date: Dec 2010
Posts: 28
Thanks: 4
Thanked 0 Times in 0 Posts
mfoland is an unknown quantity at this point
I'm thinking while having the 1-20 say start = 0 the next would say that first number... example the 41-60 say start = 41.. I can think of it, but to code it, is the hard part, well with the pagination. It is a learning experience for me!
mfoland is offline   Reply With Quote
Old 11-28-2012, 05:04 AM   PM User | #24
mfoland
New Coder

 
Join Date: Dec 2010
Posts: 28
Thanks: 4
Thanked 0 Times in 0 Posts
mfoland is an unknown quantity at this point
This is the only project I need help with.. How do I get the page to increase or decrease by say 20.. On the links I need it to echo the <?=$current?> so if I click 41-60 the page would say 41
mfoland is offline   Reply With Quote
Old 11-28-2012, 05:12 AM   PM User | #25
KULP
Regular Coder

 
Join Date: Mar 2012
Posts: 166
Thanks: 5
Thanked 11 Times in 11 Posts
KULP is an unknown quantity at this point
Quote:
Originally Posted by mfoland View Post
This is the only project I need help with.. How do I get the page to increase or decrease by say 20.. On the links I need it to echo the <?=$current?> so if I click 41-60 the page would say 41
What do you mean by 'the page would say 41'
KULP is offline   Reply With Quote
Old 11-28-2012, 05:15 AM   PM User | #26
mfoland
New Coder

 
Join Date: Dec 2010
Posts: 28
Thanks: 4
Thanked 0 Times in 0 Posts
mfoland is an unknown quantity at this point
Quote:
Originally Posted by KULP View Post
What do you mean by 'the page would say 41'
?page=41

That!

So when I click on the link it goes by 20s instead of one.

EDIT.. I'll give you an example.. The default is page= 0 so 1-20 should be bold.. although it doesn't for that. But then if I click 21-40 the page variable will be ?page=21, and so on.
mfoland is offline   Reply With Quote
Old 11-28-2012, 05:17 AM   PM User | #27
KULP
Regular Coder

 
Join Date: Mar 2012
Posts: 166
Thanks: 5
Thanked 11 Times in 11 Posts
KULP is an unknown quantity at this point
Quote:
Originally Posted by mfoland View Post
?page=41

That!

So when I click on the link it goes by 20s instead of one.
That can be changed but... why?... Is the rest of the page already coded to work that way or something?
KULP is offline   Reply With Quote
Old 11-28-2012, 05:21 AM   PM User | #28
mfoland
New Coder

 
Join Date: Dec 2010
Posts: 28
Thanks: 4
Thanked 0 Times in 0 Posts
mfoland is an unknown quantity at this point
Quote:
Originally Posted by KULP View Post
That can be changed but... why?... Is the rest of the page already coded to work that way or something?
Yes it is..
mfoland is offline   Reply With Quote
Old 11-28-2012, 05:27 AM   PM User | #29
KULP
Regular Coder

 
Join Date: Mar 2012
Posts: 166
Thanks: 5
Thanked 11 Times in 11 Posts
KULP is an unknown quantity at this point
Well you're almost there, just change a few things. I think you can play around with it enough.
KULP is offline   Reply With Quote
Users who have thanked KULP for this post:
mfoland (11-28-2012)
Old 11-28-2012, 05:28 AM   PM User | #30
mfoland
New Coder

 
Join Date: Dec 2010
Posts: 28
Thanks: 4
Thanked 0 Times in 0 Posts
mfoland is an unknown quantity at this point
Quote:
Originally Posted by KULP View Post
Well you're almost there, just change a few things. I think you can play around with it enough.
The only thing I could think of is if I change the +1 in the link to say $current it'd work, but it didn't even work.. That's why I sent the reply asking for help as to what to change.
mfoland is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:12 AM.


Advertisement
Log in to turn off these ads.