It is currently Sat Feb 04, 2012 3:39 pm

All times are UTC + 2 hours [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: show 3 records per page
PostPosted: Sun Oct 21, 2007 7:56 pm 
Offline

Joined: Thu Jul 12, 2007 4:44 am
Posts: 16
How can i show 3 records per page by using PHP if i have 20 records?

Thanks,

clodia


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 21, 2007 8:07 pm 
Offline

Joined: Sun May 02, 2004 11:34 pm
Posts: 6498
Location: toronto, canada
http://www.weberdev.com/get_example-4092.html is one example...search on paging to find more

_________________
Lostboy

Cat, the other other white meat

Please read Posting Etiquette before posting

You can always try Google


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 22, 2007 7:05 pm 
Offline

Joined: Thu Jul 12, 2007 4:44 am
Posts: 16
Thanks for the reply.

I did not know that paging is the exact keyword for showing records in multi pages. I did find a lot of examples with that keyword.

Thanks,

Clodia


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 25, 2007 4:16 pm 
Offline

Joined: Sun Jun 12, 2005 10:13 am
Posts: 15
Location: Dhaka, Bangladesh
If you are fetching records from database, then you can use LIMIT in your query string. For example, when you want 3 records per page and your DB table has 20, you can use something like:

$records = 20;
$per_page = 3;
$total_pages = ceil($records/$per_page);

Now you know $total_pages. So you can create pagination links as following:

for($page = 1; $page <= $total_pages; $page++)
{
echo "- <a rel="nofollow" href='example.php?current_page=$page'>Page $page</a> -";
}

Upon clicking on any of the page links use this code:

$current_page = 1; //by default 1

if(is_numeric($_GET['current_page']))
{
$current_page = $_GET['current_page'];
}

$record_start = ($current_page - 1) * $per_page;
$record_end = $per_page;

$query = "SELECT * FROM $table_name LIMIT $record_start, $record_end";

---------------

This is a very basic sample of pagination. I think it will help you.

Thanks.

_________________
MA Razzaque Rupom
http://rupom.wordpress.com


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 2 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron