Solved

add pagination to page

Posted on 2011-09-23
6
200 Views
Last Modified: 2012-05-12
I have the following script that displays photos and information about each member. It displays them in two columns.  Next , I need to add pagination to the page so that after it lists out 5 members in each column, another page link displays?  Also, a Next link and Previous Link.

Any idea how to do this in php or javascript?
<table align="left" border="0" width="680" cellpadding="10" cellspacing="10">
<?php
$i = 0;
foreach (get_users ("role=s2member_level1") as $user)
{
	$user = new WP_User ($user->ID);
	if ($i%2 == 0) {
		echo '<tr valign="top">';
	}

	echo '<td align="left" valign="top">';

	echo "\n" . do_shortcode("[show_avatar id=$user->ID avatar_size=120]", $user->ID) . "\n" . "<strong>Name:</strong> " . get_user_field ("display_name", $user->ID) . "\n" . "<strong>Age:</strong> " . get_user_field ("age", $user->ID) . "\n" . "<strong>County:</strong> " . get_user_field ("county", $user->ID) . "\n" . "<strong>About Me:</strong> " . get_user_field ("about_me", $user->ID) . "\n";

	echo '</td>';

	if ($i%2 != 0) {
		echo '</tr>';
	}
	$i++;
}
?>
</table>

Open in new window

0
Comment
Question by:COwebmaster
6 Comments
 
LVL 11

Accepted Solution

by:
maeltar earned 250 total points
ID: 36588163
You can do this with your sql query using the LIMIT functionality.

As in :

page 1 = select * from table limit 0, 5
page2 = select * from table limit 5, 10
page 3 = select * from table limit 10, 15

0
 

Author Comment

by:COwebmaster
ID: 36588175
is there a way to grow out those pages dynamcially though?  Do you have an example?
0
 
LVL 11

Assisted Solution

by:maeltar
maeltar earned 250 total points
ID: 36588283
if you do a mysql_num_rows then divide that by 5 you will get how many pages you need so can build the links/numbering dynamically :

http://php.about.com/od/phpwithmysql/ss/php_pagination.htm

http://www.sitepoint.com/perfect-php-pagination/

http://www.phpfreaks.com/tutorial/basic-pagination
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 27

Assisted Solution

by:Lukasz Chmielewski
Lukasz Chmielewski earned 125 total points
ID: 36588976
You can read this:
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Databases/A_4742-Simple-PHP-pagination.html

it may be helpful to you. If you need any asisst, feel free to ask.
0
 
LVL 109

Assisted Solution

by:Ray Paseur
Ray Paseur earned 125 total points
ID: 36590747
The canonical article on PHP pagination is here:
http://www.sitepoint.com/perfect-php-pagination/
0
 

Author Closing Comment

by:COwebmaster
ID: 36926429
Thanks!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The purpose of this video is to demonstrate how to exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question