add pagination to page

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">
$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>';

Open in new window

Who is Participating?
maeltarConnect With a Mentor Commented:
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

COwebmasterAuthor Commented:
is there a way to grow out those pages dynamcially though?  Do you have an example?
maeltarConnect With a Mentor Commented:
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 :
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Lukasz ChmielewskiConnect With a Mentor Commented:
You can read this:

it may be helpful to you. If you need any asisst, feel free to ask.
Ray PaseurConnect With a Mentor Commented:
The canonical article on PHP pagination is here:
COwebmasterAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.