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 (1) Thread Tools Search this Thread Display Modes
Old 09-24-2007, 11:33 PM   1 links from elsewhere to this Post. Click to view. #1 (permalink)
The Frequenter
Prolific Welcomer Upcoming Programmer 
 
Join Date: Sep 2007
Posts: 360
Thanks: 24
Haris is on a distinguished road
Default How to paginate the fetched data from the database?

How to paginate the fetched data (10 rows per page) from mysql_fetch_array?
Haris is offline  
Reply With Quote
Old 09-24-2007, 11:56 PM   #2 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,267
Thanks: 90
Wildhoney is on a distinguished road
Default

Pagination really deserves a whole new tutorial, but I've written this basic one out for you to direct you down the right path. As you can see, I've hard-coded both the array and the $iCount variable, but these will be made up of two MySQL calls in your case:
  • SELECT COUNT(*) FROM myTable
  • SELECT myColumn1, myColumn2 from myTable.

Respectively.

PHP Code:
aPages = array('Pear''Orange''Grape''Kiwi''Mango''Red Pitaya''Melon''Lime''Lemon''Banana''Apple');
$iCount count($aPages);
$iPerPage 5;
$iCurPage = isset($_GET['page']) ? $_GET['page'] : 0;

$iUpper $iCurPage $iPerPage;

for(
$iIndex $iCurPage$iIndex $iUpper$iIndex++)
{
    if(!isset(
$aPages[$iIndex]))
    {
        break;
    }
    
    echo 
'Page: ' $aPages[$iIndex] . '<br />';
}

if(
$iCurPage >= $iPerPage)
{
    
$iPreviousPage $iCurPage $iPerPage;
    echo 
'<a href="pag.php?page=' $iPreviousPage '">Previous</a> ';
}

if(
$iCount $iCurPage $iPerPage)
{
    
$iNextPage $iCurPage $iPerPage;
    echo 
' <a href="pag.php?page=' $iNextPage '">Next</a>';

__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 11-26-2007, 09:43 AM   #3 (permalink)
The Acquainted
 
EyeDentify's Avatar
 
Join Date: Nov 2007
Location: Sweden
Posts: 106
Thanks: 13
EyeDentify is on a distinguished road
Default

Looking forward to a detailed pagination tutorial.

I have always seemed to have some problems thinking in the right direction regarding these things ;)

/EyeDentifty
__________________
Of course the whole point of a doomsday machine, would have been lost if you keep it a secret.
EyeDentify is offline  
Reply With Quote
Old 11-26-2007, 09:38 PM   #4 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,267
Thanks: 90
Wildhoney is on a distinguished road
Default

You are hopeful, EyeDentify :) ! I'll give you that.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Reply


LinkBacks (?)
LinkBack to this Thread: http://www.talkphp.com/absolute-beginners/1221-how-paginate-fetched-data-database.html
Posted By For Type Date
Yahoo! Answers - PHP & MYSQL doubt? This thread Refback 01-05-2008 04:08 PM

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


All times are GMT. The time now is 02:15 AM.

 
     

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