[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

add pagination to page

Posted on 2011-09-23
6
Medium Priority
?
207 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
Looking for a new Web Host?

Lunarpages' assortment of hosting products and solutions ensure a perfect fit for anyone looking to get their vision or products to market. Our award winning customer support and 30-day money back guarantee show the pride we take in being the industry's premier MSP.

 
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

Looking for a new Web Host?

Lunarpages' assortment of hosting products and solutions ensure a perfect fit for anyone looking to get their vision or products to market. Our award winning customer support and 30-day money back guarantee show the pride we take in being the industry's premier MSP.

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
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 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…
Suggested Courses

656 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