Solved

add pagination to page

Posted on 2011-09-23
6
197 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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 108

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

In order to have all security and back ups taken care of, WordPress users can sign up for services with WP Engine.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The purpose of this video is to demonstrate how to Test the speed of a WordPress Website. Site Speed is an important metric of a site’s health. Slow site speed can result in viewers leaving your site quickly and not seeing your content. This…
The viewer will learn how to count occurrences of each item in an array.

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now