TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 06-14-2009, 03:09 AM   #1 (permalink)
The Acquainted
 
Randy's Avatar
 
Join Date: May 2007
Location: Your G/F's Closet
Posts: 114
Thanks: 7
Randy is on a distinguished road
Default Pagination

So i know this has been asked a billion times (maybe a trillion but idk), but i tried google, tutorial sites, the search feature here and nothing seems to be working for me i keep getting errors or its not what i need so here i come asking for help again.

I have this to display my data as it is designed to function as a forum but im calling it 'admin notes' in my script.
PHP Code:
            <?php
            
while($rows mysql_fetch_array($admin_forum_result)) {
            
$dateformat "M j, Y";
            
?>
            <tr>
                <td class="table_check"><input type="checkbox" class="noborder" /></td>
                <td class="table_date"><? echo date($dateformat ,$rows['datetime']); ?></td>
                <td class="table_title"><? echo $rows['topic']); ?></td>
                <td><? echo $rows['category']); ?></td>
                <td><? echo $rows['priority']); ?></td>
                <td><? echo $rows['username']); ?></td>
            </tr>
            
            <?php ?>
I want to use pagination to display 5 rows (topics) per page..

My database looks like this:
DB NAME = staff
TABLE NAME = adminforum_question
ROWS = id, topic, message, name, datetime, priority, category

Every tutorial i read kept giving me errors and i got frustrated figuring it out so.

Any help is appreciated.
__________________
Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25 - Andrew Rutherford
Send a message via AIM to Randy Send a message via MSN to Randy
Randy is offline  
Reply With Quote
Old 06-14-2009, 04:16 AM   #2 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 687
Thanks: 240
codefreek is on a distinguished road
Default

You should take a look at this, i know some people who this has helped very much including me, also it's basic + it's a video it's great. Check it out if you don't understand it, let us know but watch it at least 2,3 times.. it takes a while for it to sink in to the head/brain but it will as everything does ;)

PHP Pagination - Part 1

-Cf
__________________
I will be Offline for a while, (Working)..
codefreek is offline  
Reply With Quote
The Following 2 Users Say Thank You to codefreek For This Useful Post:
knight13 (06-14-2009), Randy (06-14-2009)
Old 06-14-2009, 05:16 AM   #3 (permalink)
The Acquainted
 
Randy's Avatar
 
Join Date: May 2007
Location: Your G/F's Closet
Posts: 114
Thanks: 7
Randy is on a distinguished road
Default

Thanks abunch mate! worked perfectly while making me laugh at the same time. Did everything i needed just on part 1 not sure if part 2 does anything more but im going to watch it. thanks.
__________________
Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25 - Andrew Rutherford
Send a message via AIM to Randy Send a message via MSN to Randy
Randy is offline  
Reply With Quote
Old 06-14-2009, 07:06 AM   #4 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 687
Thanks: 240
codefreek is on a distinguished road
Default

np mate ;)
__________________
I will be Offline for a while, (Working)..
codefreek is offline  
Reply With Quote
Old 06-14-2009, 07:28 AM   #5 (permalink)
The Acquainted
 
Randy's Avatar
 
Join Date: May 2007
Location: Your G/F's Closet
Posts: 114
Thanks: 7
Randy is on a distinguished road
Default

Alright read that got a question:

I am trying to make it display all page numbers without doing the "..." things and I cant seem to figure out how I would go about doing that lol.

My code is pretty much exactly the same as his, but his code seems quite messy in my opinion.

Any thoughts?

PHP Code:
            <?php
            
            
// define variables
            
$pageNumber = (isset($_GET["page"]) && is_numeric($_GET["page"])) ? $_GET["page"] : 1;
            
            
// establish number per page
            
$perPage 5;
            
            
// establish padding value
            
$padding 2;
            
            
// get start index of results
            
$startIndex = ($pageNumber $perPage) - $perPage;
            
            
// get total number of database entries
            
$totalCount "SELECT COUNT(*) as 'Total' FROM adminforum_question";
            
$rsCount mysql_query($totalCount) or die(mysql_error());
            
$rowCount mysql_fetch_object($rsCount);
            
            
// show page listings
            
echo "<div class=\"pagination\">";
            
                
// get total number of pages
                
$numOfPages ceil($rowCount->Total $perPage);
                
                
// print link to first page
                
if (($pageNumber != 0) && ($PageNumber != 1) && ($pageNumber != $numOfPages)) {
                }
                
?>
                
                <span class="pages">Page <?php echo $pageNumber ?> of <?php echo $numOfPages ?> </span>
                
                <?php
                
// if our current page, minus padding, greater tthen 1
                
if (($pageNumber $padding) > 1) {
                    echo 
"... ";
                        
// set lower limit
                        
$lowerLimit $pageNumber $padding;
                        
// print all padded numbers between lowerlimit and current page
                        
for($i $lowerLimit$i $pageNumber$i++) {
                            echo 
"<a href=\"index.php?page=".$i."\">".$i."</a> ";
                        }
                } else {
                    
// print all numbers between current page and first page
                    
for($i 2$i $pageNumber$i++) {
                        echo 
"<a href=\"index.php?page=".$i."\">".$i."</a> ";
                    }
                }
                
                
// if were not on first page, or last page, print current page
                
if (($pageNumber != 0) && ($PageNumber != 1) && ($pageNumber != $numOfPages)) {
                    echo 
"<b> - " $pageNumber ." - </b>";    
                }
                
                
// if current page, plus padding, less then total number of pages
                
if(($pageNumber $padding) < $numOfPages) {
                    
//  set upper limit
                    
$upperLimit $pageNumber $padding;
                    
// print all numbers from padding pages above current page
                    
for($i = ($upperLimit +1); $i $pageNumber$i++) {
                        echo 
"<a href=\"index.php?page=".$i."\">".$i."</a> ";
                    }
                    echo 
"... ";
                } else {
                    
// print all page numbers between number of pages and current page
                    
for($i = ($pageNumber 1); $i $numOfPages$i++) {
                        echo 
"<a href=\"index.php?page=".$i."\">".$i."</a> ";
                    }
                }

            echo 
"</div>";
?>
Basically I want it to look like this:
__________________
Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25 - Andrew Rutherford

Last edited by Randy : 06-14-2009 at 07:30 AM. Reason: added image
Send a message via AIM to Randy Send a message via MSN to Randy
Randy is offline  
Reply With Quote
Old 06-14-2009, 08:30 AM   #6 (permalink)
The Frequenter
 
knight13's Avatar
 
Join Date: Jun 2009
Location: Cleveland,Ohio
Posts: 430
Thanks: 30
knight13 is on a distinguished road
Default

Thanks from me also codefreek i was just about to ask basically the same question as Randy did and now i do not have to wait for an answer.
knight13 is offline  
Reply With Quote
Old 06-14-2009, 09:41 AM   #7 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,053
Thanks: 115
Tanax is on a distinguished road
Default

Pagination class
__________________
Tanax is offline  
Reply With Quote
Old 06-14-2009, 05:48 PM   #8 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 687
Thanks: 240
codefreek is on a distinguished road
Default

Randy: just take out the echo "... ";
knight13: i am glad that it helped ;)
__________________
I will be Offline for a while, (Working)..
codefreek is offline  
Reply With Quote
Old 06-14-2009, 07:24 PM   #9 (permalink)
The Acquainted
 
Randy's Avatar
 
Join Date: May 2007
Location: Your G/F's Closet
Posts: 114
Thanks: 7
Randy is on a distinguished road
Default

I figured that but there is a problem because those echo's don't even seem to show up... i just get the 'Page 1 of 3' nothing else works.
__________________
Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25 - Andrew Rutherford
Send a message via AIM to Randy Send a message via MSN to Randy
Randy is offline  
Reply With Quote
Old 06-14-2009, 09:26 PM   #10 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 687
Thanks: 240
codefreek is on a distinguished road
Default

You should take a look at Tanax's Pagination class as well..
__________________
I will be Offline for a while, (Working)..
codefreek is offline  
Reply With Quote
Old 06-15-2009, 01:28 AM   #11 (permalink)
The Acquainted
 
Randy's Avatar
 
Join Date: May 2007
Location: Your G/F's Closet
Posts: 114
Thanks: 7
Randy is on a distinguished road
Default

Watched it for the 5th time and i did my styling while following along instead of after and its working, i guess i was just getting confused with his coding style mixed with mine.

SCREENSHOT OF MY WORK
__________________
Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25 - Andrew Rutherford

Last edited by Randy : 06-15-2009 at 05:00 PM.
Send a message via AIM to Randy Send a message via MSN to Randy
Randy is offline  
Reply With Quote
Old 06-15-2009, 02:04 PM   #12 (permalink)
The Frequenter
 
knight13's Avatar
 
Join Date: Jun 2009
Location: Cleveland,Ohio
Posts: 430
Thanks: 30
knight13 is on a distinguished road
Default

I know this will probably be a stupid question but i have to ask. In the below script where is the $_GET['page'] coming from.

I understand what a ternary operator is but i do not know where the $_GET['page'] is coming from.

PHP Code:
$PageNumber = (isset($_GET['page'])&& is_numeric($_GET['page'])) ? $_GET['paget'] : 1
This is the code from the video that Codefreek posted.
knight13 is offline  
Reply With Quote
Old 06-15-2009, 03:14 PM   #13 (permalink)
The Acquainted
 
Randy's Avatar
 
Join Date: May 2007
Location: Your G/F's Closet
Posts: 114
Thanks: 7
Randy is on a distinguished road
Default

I may be wrong so dont quote me on it but i believe that is a basic php function where it reads something in the url. i know its a long shot but its all i got.
__________________
Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25 - Andrew Rutherford
Send a message via AIM to Randy Send a message via MSN to Randy
Randy is offline  
Reply With Quote
Old 06-15-2009, 03:55 PM   #14 (permalink)
The Frequenter
 
knight13's Avatar
 
Join Date: Jun 2009
Location: Cleveland,Ohio
Posts: 430
Thanks: 30
knight13 is on a distinguished road
Default

Yea the $_GET[''] gets something out of the url but i do not understand what, because in it is the page but where does the page come from and that is what is confusing me.
knight13 is offline  
Reply With Quote
Old 06-15-2009, 04:59 PM   #15 (permalink)
The Acquainted
 
Randy's Avatar
 
Join Date: May 2007
Location: Your G/F's Closet
Posts: 114
Thanks: 7
Randy is on a distinguished road
Default

nah the $_GET[''] gets something from the url if its not defined by a form, but i believe 'page' is what retrieves a number from the end.
__________________
Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25 - Andrew Rutherford
Send a message via AIM to Randy Send a message via MSN to Randy
Randy is offline  
Reply With Quote
Old 06-15-2009, 05:05 PM   #16 (permalink)
The Frequenter
 
knight13's Avatar
 
Join Date: Jun 2009
Location: Cleveland,Ohio
Posts: 430
Thanks: 30
knight13 is on a distinguished road
Default

From the end of what?
knight13 is offline  
Reply With Quote
Old 06-15-2009, 05:08 PM   #17 (permalink)
The Acquainted
 
Randy's Avatar
 
Join Date: May 2007
Location: Your G/F's Closet
Posts: 114
Thanks: 7
Randy is on a distinguished road
Default

from the url but here is what your looking for:

Your URL is like this correct:
index.php?page=9

by putting $_GET['page'] you are telling it to put page there so change page to whatever you want to be there such as id, number, etc.. and then it reads the number after page=.
__________________
Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25 - Andrew Rutherford
Send a message via AIM to Randy Send a message via MSN to Randy
Randy is offline  
Reply With Quote
Old 06-16-2009, 05:05 AM   #18 (permalink)
The Frequenter
 
knight13's Avatar
 
Join Date: Jun 2009
Location: Cleveland,Ohio
Posts: 430
Thanks: 30
knight13 is on a distinguished road
Default

OK i should have looked at the code a little longer thanks!
knight13 is offline  
Reply With Quote
Old 06-16-2009, 05:32 AM   #19 (permalink)
The Acquainted
 
Randy's Avatar
 
Join Date: May 2007
Location: Your G/F's Closet
Posts: 114
Thanks: 7
Randy is on a distinguished road
Default

no problem lol honestly took me about 15 mins reading that line over and over to figure it out, sorry if its not the exact explanation your looking for, im not the best at explaining so I did best I could.
__________________
Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25 - Andrew Rutherford
Send a message via AIM to Randy Send a message via MSN to Randy
Randy is offline  
Reply With Quote
Old 06-16-2009, 07:07 AM   #20 (permalink)
The Contributor
 
Join Date: Jun 2009
Location: Seattle, WA
Posts: 79
Thanks: 1
rguy84 is on a distinguished road
Default

Quote:
Originally Posted by knight13 View Post
PHP Code:
$PageNumber = (isset($_GET['page'])&& is_numeric($_GET['page'])) ? $_GET['paget'] : 1
Without looking at the code, it seems as though it needs a counter.
__________________
Ryan | Blog | Twitter
Send a message via AIM to rguy84 Send a message via MSN to rguy84 Send a message via Yahoo to rguy84 Send a message via Skype™ to rguy84
rguy84 is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Pagelite Pagination System ioan1k Show Off 0 03-15-2009 02:22 AM
Pagination rupam_jaiswal Javascript, AJAX, E4X 0 09-09-2008 09:34 AM
Pagination, Funtions, Converting CMellor Absolute Beginners 2 12-23-2007 10:53 PM
Advance Pagination Class Rendair Advanced PHP Programming 9 12-13-2007 08:28 AM
Pagination Or Something Else? Randy General 2 09-14-2007 01:44 PM


All times are GMT. The time now is 01:51 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design