user_friends_count - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of user_friends_count.php

  1. <?php
  2. function cot_social_remove_friend($userid, $friendid)
  3. {
  4.                 $sql1 = $db->query("SELECT * FROM $db_cot_social_friendslist WHERE userid = $userid AND friendid = $friendid LIMIT 1");
  5.                 $execute1 = $sql1->rowCount();
  6.                 $sql2 = $db->query("SELECT * FROM $db_cot_social_friendslist WHERE userid = $friendid AND friendid = $userid LIMIT 1");
  7.                 $execute2 = $sql2->rowCount();
  8.                 if($execute1 > 0){$data = $sql1->fetch();}
  9.                 if($execute2 > 0){$data = $sql2->fetch();}
  10.                 $db->delete($db_cot_social_friendslist, "id='".$data['id']."' LIMIT 1");
  11.                 $friendscount_userid = $db->query("SELECT user_friends_count FROM $db_users WHERE user_id=" . $userid)->fetchColumn();
  12.                 $friendscount_friendid = $db->query("SELECT user_friends_count FROM $db_users WHERE user_id=" . $friendid)->fetchColumn();
  13.                 if ($friendscount_userid>0)
  14.                 {
  15.                         $db->query("UPDATE $db_users SET user_friends_count=user_friends_count-1 WHERE user_id=" . $userid);
  16.                 }
  17.                 if ($friendscount_friendid>0)
  18.                 {
  19.                         $db->query("UPDATE $db_users SET user_friends_count=user_friends_count-1 WHERE user_id=" . $friendid);
  20.                 }
  21. }
  22.  
File Description
  • user_friends_count
  • PHP Code
  • 24 Jun-2021
  • 1.05 Kb
You can Share it: