php - limit amount of friends to 12 shown in a box? -


i have box displays friends of user, however, shows them , stretched off canvas of app. have them in table in box, there anyway limit amount shown 12 random friends?

this code display friends:

if ($user) { $user_profile = $facebook->api('/me'); $friends = $facebook->api('/me/friends');  echo '<table>'; foreach ($friends["data"] $value) {     echo '<td>';     echo '<div class="pic">';     echo '<img src="https://graph.facebook.com/' . $value["id"] . '/picture"/>';     echo '</div>';     echo '<font color="white">','<div class="picname">'.$value["name"].'</div>','</font>';     echo '</td>'; } echo '</table>'; } ?> 

you could, instance, use break statement exit loop. use this:

if ($user) {     $user_profile = $facebook->api('/me'); $friends = $facebook->api('/me/friends');  $counter = 1;  echo '<table>'; foreach ($friends["data"] $value) {     echo '<td>';     echo '<div class="pic">';     echo '<img src="https://graph.facebook.com/' . $value["id"] . '/picture"/>';     echo '</div>';     echo '<font color="white">','<div class="picname">'.$value["name"].'</div>','</font>';     echo '</td>';      if ($counter >= 12) {         break;     }     $counter = $counter + 1; } echo '</table>'; } 

a more advanced approach make use of array_slice() function, modifies arrays. @ 12 elements, starting @ position 0, of $friends['data'] foreach loop, write:

// code... foreach (array_slice($friends["data"], 0, 12) $value) {     // code... 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -