shorty3 Posted May 12, 2010 Share Posted May 12, 2010 ive coded this <? $query_friends=mysql_query("SELECT * FROM friends WHERE username='$viewuser' AND type='Friend'"); $rows=mysql_num_rows($query_friends); if ($rows == "0"){ echo "<center>No friends</center>"; } while($dip=mysql_fetch_object($query_friends)){ echo " <a href='profile.php?viewuser=$dip->person'>$dip->person</a>,"; } ?> but i want it to have a limit of 3 friends in a row and then a <br> and so on example what its doing now username, username, username, username................. what i want it to do is username, username, username username, username, username username, username, username and also how can i have it add up all the friends so i can have example: friends 83 somthing like <?php echo "$rows";?> Link to comment https://forums.phpfreaks.com/topic/201500-limit-array-to-3/ Share on other sites More sharing options...
trq Posted May 12, 2010 Share Posted May 12, 2010 See http://www.phpfreaks.com/forums/index.php/topic,95426.0.html Link to comment https://forums.phpfreaks.com/topic/201500-limit-array-to-3/#findComment-1057139 Share on other sites More sharing options...
shorty3 Posted May 12, 2010 Author Share Posted May 12, 2010 im still none the wiser i dont know how to implement that in the code i have, with the help you gave me Link to comment https://forums.phpfreaks.com/topic/201500-limit-array-to-3/#findComment-1057263 Share on other sites More sharing options...
mattyvx Posted May 12, 2010 Share Posted May 12, 2010 you need to set a variable to start with before your while loop, check if it is divisible by 3, then increment <? $rows=mysql_num_rows($query_friends); if ($rows == "0"){ echo "<center>No friends</center>"; } $friend = 0; while($dip=mysql_fetch_object($query_friends)) { echo ($friend % 3 == 0)? "<br/>" : ""; // checks if friend number is a multiple of three if yes echo <br/> if not echo nothing echo " <a href='profile.php?viewuser=$dip->person'>$dip->person</a>,"; // echo link to friend profile $friend++; // increase friend count } ?> That should work i think (not tested) Link to comment https://forums.phpfreaks.com/topic/201500-limit-array-to-3/#findComment-1057288 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.