Hi everyone. I am seeking help to display my query result (user list) into several pages. The code below retrieves user details successfully like a picture, accommodation name, address and a clickable link to a profile page related to specific details of user. This page is my users_list.php which displays the details from my mysql database.
The user details gets display but I am trying to limit the display (user details) to 10 rows of data from database in user_list.php The problem I have is that more than 10 rows gets displayed on the page (I actually have 12 rows of data (user details) saved in database). How do I limit details to 10 rows of data per page?
The pagination script I have gets display correctly but when I click through to page 2 on user_list.php the same user details from page 1 also get displayed. I have 12 user details (rows) saved in database. All 12 get displayed on page 1 and 2 in user_list.php
The fields I am retrieving from database are avatar_url, acc_name and address. The picture (avartar_url) are saved to a folder (images/avatars) with the picture url saved to the database.
Can anyone please provide help to solve my problem. My code from users_list.php is below.
Apreciate your help
Thanks.

<?php
include 'dbc.php';
include 'includes/title.inc.php';
include 'includes/ps_pagination.php';

/******************** ADD ME TO SHOW USERS AVATAR ****************************/
$img_url_query = mysql_query("select avatar_url from users where id = '$_SESSION[user_id]'");
while($img_url_settings = mysql_fetch_array($img_url_query)) {
$img_url = $img_url_settings['avatar_url'];
}
/*****************************************************************************/

?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="css/default.css" type="text/css" media="screen"/>
<title>Places To Stay In The Eastern Cape<?php if (isset($title)) {echo "&#8212;{$title}";} ?></title>

</head>

<body>

<h3 class="titlehdr">List Users</h3>
      <p>Here you can view all registered users.</p><br />

<?php
$result = mysql_query("select * from users");
while($row = mysql_fetch_array($result)) { 

echo 
"<table class='tableuser' bgcolor='#FFDB94' cellspacing='0' cellpadding='0' border='0'>
<tr>
<td class='tduser' width='20%' align='center' valign='middle' bgcolor='#FFCC66'><p><img src=\"images/avatars/{$row['avatar_url']}\"$avatar_url\" width='100' border='1' /></p></td>
<td class='tduser' width='20%' align='center' valign='middle'><p>".$row['acc_name']."</p></td>
<td class='tduser'width='20%' align='center' valign='middle'><p>".$row['address']."</p></td>
<td class='tduser' width=20% align='center' valign='middle'><a href='profile.php?id=".$row['id']."'>".$row['acc_name']."</td>
</tr>
</table>";
}
?>
<div id="pagination">
  <?php
	//Connect to mysql db
	$conn = mysql_connect('localhost','admin123','jegg123');
	if(!$conn) die("Failed to connect to database!");
	$status = mysql_select_db('register', $conn);
	if(!$status) die("Failed to select database!");
	$sql = 'SELECT * FROM users';
	
	/*
	 * Create a PS_Pagination object
	 * 
	 * $conn = MySQL connection object
	 * $sql = SQl Query to paginate
	 * 10 = Number of rows per page
	 * 5 = Number of links
	 * "param1=valu1&param2=value2" = You can append your own parameters to paginations links
	 */
	$pager = new PS_Pagination($conn, $sql, 10, 5, 'param1=value1&param2=value2');
	
	/*
	 * Enable debugging if you want o view query errors
	*/
	$pager->setDebug(true);
	
	/*
	 * The paginate() function returns a mysql result set
	 * or false if no rows are returned by the query
	*/
	$rs = $pager->paginate();
	if(!$rs) die(mysql_error());
	while($row = mysql_fetch_assoc($rs)) {
		echo $row['image'],"<br />\n";
	}
	
	//Display the full navigation in one go
	//echo $pager->renderFullNav();
	
	//echo "<br />\n";
	
	/*
	 * Or you can display the individual links for more
	 * control over HTML rendering.
	 * 
	*/
	
	//Display the link to first page: First
	echo $pager->renderFirst();
	
	//Display the link to previous page: <<
	echo $pager->renderPrev();
	
	/*
	 * Display page links: 1 2 3
	 * $prefix = Will be prepended to the page link (optional)
	 * $suffix = Will be appended to the page link (optional)
	 * 
	*/
	echo $pager->renderNav('<span>', '</span>');
	
	//Display the link to next page: >>
	echo $pager->renderNext();
	
	//Display the link to last page: Last
	echo $pager->renderLast();
    ?>
</div>

</body>
</html>

worth while link to check out is http://www.lotsofcode.com/php/php-array-pagination.htm

i used that as the base of a pagination script for my current project, modified to suit my purpose however i think would be modifyable for yours as well.

I am also aware that pagination can be done via the database within your SQL Query.

Have a look at using LIMIT = 10 within your SQL at the end.

Hope this helps you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.