$rows = $db->selectPage($total, "(SELECT * FROM friends f1
LEFT JOIN friends f2 ON (f1.friend1 = f2.friend2 AND f2.friend1 = f1.friend2)
LEFT JOIN users u ON (f1.friend2 = u.user_id OR f2.friend1 = u.user_id)
LEFT JOIN users_visits v ON u.user_id = v.visit_id
WHERE f1.friend1 = ".$userid." AND v.visit_now_time > '".(SITE_TIME-600)."')
UNION
(SELECT * FROM friends f1
RIGHT JOIN friends f2 ON (f1.friend1 = f2.friend2 AND f2.friend1 = f1.friend2)
LEFT JOIN users u ON (f1.friend1 = u.user_id OR f2.friend1 = u.user_id)
LEFT JOIN users_visits v ON u.user_id= v.visit_id
WHERE f2.friend2 = ".$userid." AND v.visit_now_time > '".(SITE_TIME-600)."')
);