The best way to find any number of random entries is by using OFFSET in the query.
Say you want 6 random entries, so I’ll get the answer above and calculate the total number of friends in the database.
$sql = mysql_query("SELECT COUNT(*) AS total FROM friends WHERE member_id='". $_SESSION['userid'] ."'"); $get_count = mysql_fetch_array($sql); // Fetch the results $numfriends = $get_count['total']; // We've gotten the total number
Now we get 6 random entries from the total above (hopefully this is> 6),
$query = mysql_query("SELECT * FROM friends WHERE member_id='". $_SESSION['userid'] ."' LIMIT 6 OFFSET " . (rand(0, $numFriends)); while ($rows = mysql_fetch_array($query)) {
Using OFFSET may not be the best or most effective, but it worked for me in large databases without linking them.
Jan michaels
source share