forgot password?
need an account?

Notifications close x

WI2 add on Friend Suggestions

loading social widgets...
LewisAndersonWritten By: LewisAnderson   flag
Publish Date: January 10, 2015
Code for the webintersect 2 add on More Friends Suggestions
<?php include_once("php_includes/check_login_status.php"); // Make sure the user is logged in if(isset($_SESSION['username'])){ $u = $_SESSION['username']; } else { echo "You need to be logged in."; exit(); } // Initialize Some Things $moMoFriends = ""; $my_friends = array(); $their_friends = array(); // Get Friend Array $sql = "SELECT user1, user2 FROM friends WHERE (user1='$u' OR user2='$u') AND accepted='1'"; $query = mysqli_query($db_conx, $sql); $numrows = mysqli_num_rows($query); if ($numrows > 0){ while($row = mysqli_fetch_array($query, MYSQLI_ASSOC)){ array_push($my_friends, $row["user2"]); array_push($my_friends, $row["user1"]); } //remove your id from array $my_friends = array_diff($my_friends, array($u)); //reset the key values $my_friends = array_values($my_friends); mysqli_free_result($query); } // Get Friends Of Friends Array // Exclude Yourself From Query foreach ($my_friends as $k => $v) { // You may want to edit limit at end of following query ....example... LIMIT 50 $sql = "SELECT user1, user2 FROM friends WHERE (user1='$v' OR user2='$v') AND accepted='1' AND user1!='$u' AND user2!='$u' LIMIT 20"; $query = mysqli_query($db_conx, $sql); $numrows = mysqli_num_rows($query); if ($numrows > 0){ while($row = mysqli_fetch_array($query, MYSQLI_ASSOC)){ array_push($their_friends, $row["user2"]); array_push($their_friends, $row["user1"]); } } //remove any duplicates $their_friends = array_unique($their_friends); // remove common friends $their_friends = array_diff($their_friends, $my_friends); // reset array values $their_friends = array_values($their_friends); mysqli_free_result($query); } // Build Output From Results if (array_key_exists('0', $their_friends)){ $moMoFriends = '<div id="moMoFriends">'; $moMoFriends .= '<h2>People You May Like</h2>'; foreach ($their_friends as $k2 => $v2){ $query = mysqli_query($db_conx, "SELECT avatar FROM users WHERE username='$v2'LIMIT 1"); while($row = mysqli_fetch_array($query, MYSQLI_ASSOC)){ $moMoFriends .= '<a href="user.php?u='.$v2.'"><img src=" user/'.$v2.'/'.$row["avatar"].'" alt="'.$v2.'" title="'.$v2.'" width="80px"></a>&nbsp;&nbsp;'; } } $moMoFriends .= '</div>'; } ?> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <link rel="stylesheet" href="style/style.css"> </head> <body> <?php include_once("template_pageTop.php"); ?> <div id="pageMiddle"><?php echo $moMoFriends ?></div> <?php include_once("template_pageBottom.php"); ?> </body> </html>
You can read more articles by LewisAnderson by clicking this link:
Articles written by LewisAnderson

User Notes And Comments ↓

Saturday January 10, 2015 06:36:56 AM
root said:Greate tut :D
Wednesday May 18, 2016 03:41:33 PM
herbertbruce8gm said:Thanks Lewis we appreciate your efforts everything is good please keep that spirit
© 2015 webintersect.com
There is a top-shelf free educational course of videos associated with this domain, all about how to build custom communities and social network websites. There are over 45 videos in the course totaling just over 10 hours. We also archived the deprecated course material here for you to reference on the source files page.