pagination on friendlist

Hi I am having trouble figuring out how to paginate my friendlist.
Right now it assembles friends list and views up to 500.
I want to use paginate instead can anyone help me with how to do this?

[php]// ------- POPULATE FRIEND DISPLAY LISTS IF THEY HAVE AT LEAST ONE FRIEND -------------------
$friendList = “”;
$friendPopBoxList = “”;
if ($friend_array != “”) {
// ASSEMBLE FRIEND LIST AND LINKS TO VIEW UP TO 6 ON PROFILE
$friendArray = explode(",", $friend_array);
$friendCount = count($friendArray);
$friendArray6 = array_slice($friendArray, 0, 6);

$friendList .= '<div class="friend_h"> <h2>Connections</h2> <h7>(<a href="#" onclick="return false" onmousedown="javascript:toggleViewAllFriends(\'view_all_friends\');">' . $friendCount . '</a>)</h7></div>';
$i = 0; // create a varible that will tell us how many items we looped over 
 $friendList .= '<div class="friends" ><table id="friendTable" align="center" cellspacing="4"></tr>'; 
foreach ($friendArray6 as $key => $value) { 
    $i++; // increment $i by one each loop pass 
	$check_pic = 'members/' . $value . '/image01.jpg';
	    if (file_exists($check_pic)) {
			$frnd_pic = '<a href="profile.php?id=' . $value . '"><img src="' . $check_pic . '" width="54px" border="1"/></a>';
	    } else {
			$frnd_pic = '<a href="profile.php?id=' . $value . '"><img src="members/0/image01.jpg" width="54px" border="1"/></a> &nbsp;';
	    }
		$sqlName = mysql_query("SELECT username, firstname FROM myMembers WHERE id='$value' LIMIT 1") or die ("Sorry we had a mysql error!");
	    while ($row = mysql_fetch_array($sqlName)) { $friendUserName = substr($row["username"],0,12); $friendFirstName = substr($row["firstname"],0,12);}
		if (!$friendUserName) {$friendUserName = $friendFirstName;} // If username is blank use the firstname... programming changes in v1.32 call for this
		if ($i % 6 == 6){
			$friendList .= '<tr><td><div style="width:56px; height:68px; overflow:hidden;" title="' .  '">
			<a href="profile.php?id=' . $value . '">' . '</a><br />' . $frnd_pic . '
			</div></td>';  
		} else {
			$friendList .= '<td><div style="width:56px; height:68px; overflow:hidden;" title="' .  '">
			<a href="profile.php?id=' . $value . '">' . '</a><br />' . $frnd_pic . '
			</div></td>'; 
		}
} 
 $friendList .= '</tr></table>
 <div class="view"><a href="#" onclick="return false" onmousedown="javascript:toggleViewAllFriends(\'view_all_friends\');">view all</a></div>
 </div>'; 
// END ASSEMBLE FRIEND LIST... TO VIEW UP TO 6 ON PROFILE
// ASSEMBLE FRIEND LIST AND LINKS TO VIEW ALL(50 for now until we paginate the array)
$i = 0;
$friendArray50 = array_slice($friendArray, 0, 500);
$friendPopBoxList = '<table id="friendPopBoxTable" width="100%" align="center" cellpadding="6" cellspacing="0">';
foreach ($friendArray50 as $key => $value) { 
    $i++; // increment $i by one each loop pass 
	$check_pic = 'members/' . $value . '/image01.jpg';
	    if (file_exists($check_pic)) {
			$frnd_pic = '<a href="profile.php?id=' . $value . '"><img src="' . $check_pic . '" width="54px" border="1"/></a>';
	    } else {
			$frnd_pic = '<a href="profile.php?id=' . $value . '"><img src="members/0/image01.jpg" width="54px" border="1"/></a> &nbsp;';
	    }
		$sqlName = mysql_query("SELECT username, firstname, country, state, city FROM myMembers WHERE id='$value' LIMIT 1") or die ("Sorry we had a mysql error!");
	    while ($row = mysql_fetch_array($sqlName)) { $funame = $row["username"]; $ffname = $row["firstname"]; $fcountry = $row["country"]; $fstate = $row["state"]; $fcity = $row["city"]; }
		if (!$funame) {$funame = $ffname;} // If username is blank use the firstname... programming changes in v1.32 call for this
			if ($i % 2) {
				$friendPopBoxList .= '<tr bgcolor="#F4F4F4"><td width="14%" valign="top">
				<div style="width:56px; height:56px; overflow:hidden;" title="' . $funame . '">' . $frnd_pic . '</div></td>
			     <td width="86%" valign="top"><a href="profile.php?id=' . $value . '">' . $funame . '</a><br /><font size="-2"><em>' . $fcity . '<br />' . $fstate . '' . $fcountry . '</em></font></td>
			    </tr>';  
			} else {
			    $friendPopBoxList .= '<tr bgcolor="#E0E0E0"><td width="14%" valign="top">
				<div style="width:56px; height:56px; overflow:hidden;" title="' . $funame . '">' . $frnd_pic . '</div></td>
			     <td width="86%" valign="top"><a href="profile.php?id=' . $value . '">' . $funame . '</a><br /><font size="-2"><em>' . $fcity . '<br />' . $fstate . '' . $fcountry . '</em></font></td>
			    </tr>';  
			}
} 
$friendPopBoxList .= '</table>';
// END ASSEMBLE FRIEND LIST AND LINKS TO VIEW ALL(50 for now until we paginate the array)
}

// ------- END POPULATE FRIEND DISPLAY LISTS IF THEY HAVE AT LEAST ONE FRIEND -------------------[/php]

I have a working pagination script but dont know how include it the right way for the friendslist
here is that script
[php]$tableName=“countries”;
$targetpage = “index.php”;
$limit = 10;

$query = "SELECT COUNT(*) as num FROM $tableName";
$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages = $total_pages[num];

$stages = 3;
$page = mysql_escape_string($_GET['page']);
if($page){
	$start = ($page - 1) * $limit; 
}else{
	$start = 0;	
	}	

// Get page data
$query1 = "SELECT * FROM $tableName LIMIT $start, $limit";
$result = mysql_query($query1);

// Initial page num setup
if ($page == 0){$page = 1;}
$prev = $page - 1;	
$next = $page + 1;							
$lastpage = ceil($total_pages/$limit);		
$LastPagem1 = $lastpage - 1;					


$paginate = '';
if($lastpage > 1)
{	




	$paginate .= "<div class='paginate'>";
	// Previous
	if ($page > 1){
		$paginate.= "<a href='$targetpage?page=$prev'>previous</a>";
	}else{
		$paginate.= "<span class='disabled'>previous</span>";	}
		

	
	// Pages	
	if ($lastpage < 7 + ($stages * 2))	// Not enough pages to breaking it up
	{	
		for ($counter = 1; $counter <= $lastpage; $counter++)
		{
			if ($counter == $page){
				$paginate.= "<span class='current'>$counter</span>";
			}else{
				$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}					
		}
	}
	elseif($lastpage > 5 + ($stages * 2))	// Enough pages to hide a few?
	{
		// Beginning only hide later pages
		if($page < 1 + ($stages * 2))		
		{
			for ($counter = 1; $counter < 4 + ($stages * 2); $counter++)
			{
				if ($counter == $page){
					$paginate.= "<span class='current'>$counter</span>";
				}else{
					$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}					
			}
			$paginate.= "...";
			$paginate.= "<a href='$targetpage?page=$LastPagem1'>$LastPagem1</a>";
			$paginate.= "<a href='$targetpage?page=$lastpage'>$lastpage</a>";		
		}
		// Middle hide some front and some back
		elseif($lastpage - ($stages * 2) > $page && $page > ($stages * 2))
		{
			$paginate.= "<a href='$targetpage?page=1'>1</a>";
			$paginate.= "<a href='$targetpage?page=2'>2</a>";
			$paginate.= "...";
			for ($counter = $page - $stages; $counter <= $page + $stages; $counter++)
			{
				if ($counter == $page){
					$paginate.= "<span class='current'>$counter</span>";
				}else{
					$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}					
			}
			$paginate.= "...";
			$paginate.= "<a href='$targetpage?page=$LastPagem1'>$LastPagem1</a>";
			$paginate.= "<a href='$targetpage?page=$lastpage'>$lastpage</a>";		
		}
		// End only hide early pages
		else
		{
			$paginate.= "<a href='$targetpage?page=1'>1</a>";
			$paginate.= "<a href='$targetpage?page=2'>2</a>";
			$paginate.= "...";
			for ($counter = $lastpage - (2 + ($stages * 2)); $counter <= $lastpage; $counter++)
			{
				if ($counter == $page){
					$paginate.= "<span class='current'>$counter</span>";
				}else{
					$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}					
			}
		}
	}
				
			// Next
	if ($page < $counter - 1){ 
		$paginate.= "<a href='$targetpage?page=$next'>next</a>";
	}else{
		$paginate.= "<span class='disabled'>next</span>";
		}
		
	$paginate.= "</div>";		

}
echo $total_pages.’ Results’;
// pagination
echo $paginate;
?>[/php]

Here’s a basic Pagination tutorial which should help to work out howto get it in your script: Click Here

Thanks for the reply I will look into that tutorial, but I wonder if I should do anything with this part of the script [php]

// ASSEMBLE FRIEND LIST AND LINKS TO VIEW UP TO 6 ON PROFILE

$friendArray = explode(",", $friend_array);

$friendCount = count($friendArray);
$friendArray6 = array_slice($friendArray, 0, 6);[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service