Jump to content

adding pagination


davur.p

Recommended Posts

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?

 

Have a working pagination script from http://papermashup.com/easy-php-pagination/ which worked on my inbox system but cant get it to work on my friendlist.

What should I remove so I can start to insert the pagination?

 

Thanks

// ------- 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>  ';
            }
            $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>  ';
            }
            $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 -------------------  

Link to comment
Share on other sites

Thanks

will look into that :)

 

Not sure what I should remove from the current code as it shows

// 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);

 

What should I remove to insert the pagination

 

Thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.