I'm having some trouble below, currently on my social network site I count users friends which can take a lot of time on an account with 50,000+ friends so I am wanting to change over to store friend counts as a value in the DB, on 1 page I allow for a user to "approve" up to 10 friend request at a time, below is the code that does that I need to make the part where it says
////update friend count for each user that I approve
I need to loop through each friend ID in the list and take there friedn count and add + 1 to that number and update there mysql record, any help appreciated
if ($_POST['approve'] != NULL || $_GET['approve'] == yes) {
validlogin($url);
$arr = $_POST['chk'];
$cnt = count($arr);
if ($cnt > 0) {
$str_auto_ids = implode(",", $arr);
$sql = "update friend_friend set status='1' where userid in ($str_auto_ids) and friendid='$_SESSION['auto_id']'";
$result = executeQuery($sql);
$sql = "update friend_friend set status='1' where userid='$_SESSION['auto_id']' and friendid in ($str_auto_ids)";
$result = executeQuery($sql);
//update friend count for how many I approve
$sql2= 'update friend_reg_user set fcount=fcount + ' .$cnt. ' WHERE auto_id=' .$friendid;
executequery($sql2);
//update friend count for each user that I approve
$sql2= 'update friend_reg_user set fcount=fcount + ' .$cnt. ' WHERE auto_id=//EACH USER
executequery($sql2);
$msg = "User Successfully added to your friend list !";
$_SESSION['sess_msg'] = $msg;
header("location: $url");
exit;
}
}