?
Solved

add pagination to page

Posted on 2011-09-23
6
Medium Priority
?
205 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 11

Accepted Solution

by:
maeltar earned 1000 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 1000 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
WordPress Tutorial 2: Terminology

An important part of learning any new piece of software is understanding the terminology it uses. Thankfully WordPress uses fairly simple names for everything that make it easy to start using the software.

 
LVL 27

Assisted Solution

by:Lukasz Chmielewski
Lukasz Chmielewski earned 500 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 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 500 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

WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

Question has a verified solution.

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

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

777 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