-
tp45
Junior Member
-
Posts: 36
Threads: 9
Joined: Aug 2019
Reputation:
0
09-27-2019, 01:05 PM
(This post was last modified: 09-27-2019, 01:34 PM by tp45.)
hello
Am doing friend suggestion in my system so am close but i cant figure out how to access this data
so what am doing getting users to suggest and their mutual friends but i only want suggested user and as for mutual friend i just want to count them
Here is the data to see it correctly i had to view in in page source it displays nice that way:
Code: stdClass Object
(
[suggestedUser] => Array
(
[0] => Array
(
[user_id] => 11
[firstname] => Siphe
[lastname] => Jali
[username] => siphe4573
[email] => [email protected]
[dob] => 01/01/2001
[gender] => Male
[address] => 15 Western Road, Port Elizabeth Central, Port Elizabeth, South Africa
[cellno] =>
[hobby] => Drama
[cover_image] => Sipheeye-for-ebony-399310-unsplash.jpg
[image] => mink-mingle-1381133-unsplash.jpg
[video_descryption] =>
[validation_code] => 0
[is_activated] => 1
[acount_created_at] => 2019-08-11 15:00:01.000
[last_active] => 2019-09-25 15:19:31.000
[logout_time] => 2019-09-25 15:45:16.000
[password] => $2y$10$QjzY5VsfdPUqGGVSyDd63.CNlXHlZJsHPbUN16B0c6D0RY1G4i2vu
[job_name] =>
[job_title] =>
[bio] =>
[music] =>
[movies] =>
[books] =>
[animals] =>
[post_num] => 1
[blocked] => 0
[closed] => 0
[online] => 1
[friendArray] => ,bonga6367
)
)
[mutualFriends] => Array
(
[0] => Array
(
[0] => Array
(
[user_id] => 20021
[firstname] => Bongani
[lastname] => Phamela
[username] => bonga6367
[email] => [email protected]
[dob] => 02/12/1992
[gender] => Trans Person
[address] => 485 Govan Mbeki Avenue, North End, Port Elizabeth, South Africa
[cellno] =>
[hobby] => Coding, UI/UX designing and gaming..
[cover_image] => 382694-large-sniper-wallpaper-1920x1080-windows-xp.jpg
[image] => 281850-beautiful-gaming-wallpaper-2560x1440.jpg
[video_descryption] =>
[validation_code] => 0
[is_activated] => 1
[acount_created_at] => 2019-09-02 21:47:03.000
[last_active] => 2019-09-27 12:57:41.000
[logout_time] => 2019-09-27 19:00:09.000
[password] => $2y$10$fyPLhL0KPcg26gyAaGtiAuyGGnmWcxadM7vlOJaRKmoetNri8lSbe
[job_name] => Software Developer
[job_title] => Junior Software dev
[bio] => This is my bio #test @bonga6367 http://www.helo.com
[music] => Hip Hop, House, RnB
[movies] => Rocky, fast and firious
[books] => our lady of benony, red blanket
[animals] => Dog, Cat, Elephant, horse, lion
[post_num] =>
[blocked] => 0
[closed] => 0
[online] => 1
[friendArray] => ,topollo57,siphe4573,nthethe5933,kabelo3088
)
)
)
)
stdClass Object
(
[suggestedUser] => Array
(
[0] => Array
(
[user_id] => 13
[firstname] => Kabelo
[lastname] => Thalent
[username] => kabelo3088
[email] => [email protected]
[dob] => 02/02/1993
[gender] => Trans Female
[address] => Openbaring Crescent, Kamma Park, Port Elizabeth, South Africa
[cellno] =>
[hobby] =>
[cover_image] => Kabelocup_spray_drops_124059_1280x720.jpg
[image] => kal-visuals-644747-unsplash.jpg
[video_descryption] =>
[validation_code] => 0
[is_activated] => 1
[acount_created_at] => 2019-08-20 08:12:02.000
[last_active] => 2019-09-26 23:42:54.000
[logout_time] => 2019-09-26 17:23:47.000
[password] => $2y$10$EsrUNveU.vJcLkV0DExDnOYqPArnjCmThIhf1ZA3h7Bz515mw8.ti
[job_name] =>
[job_title] =>
[bio] =>
[music] =>
[movies] =>
[books] =>
[animals] =>
[post_num] => 2
[blocked] => 0
[closed] => 0
[online] => 1
[friendArray] => ,bonga6367
)
)
[mutualFriends] => Array
(
[0] => Array
(
[0] => Array
(
[user_id] => 20021
[firstname] => Bongani
[lastname] => Phamela
[username] => bonga6367
[email] => [email protected]
[dob] => 02/12/1992
[gender] => Trans Person
[address] => 485 Govan Mbeki Avenue, North End, Port Elizabeth, South Africa
[cellno] =>
[hobby] => Coding, UI/UX designing and gaming..
[cover_image] => 382694-large-sniper-wallpaper-1920x1080-windows-xp.jpg
[image] => 281850-beautiful-gaming-wallpaper-2560x1440.jpg
[video_descryption] =>
[validation_code] => 0
[is_activated] => 1
[acount_created_at] => 2019-09-02 21:47:03.000
[last_active] => 2019-09-27 12:57:41.000
[logout_time] => 2019-09-27 19:00:09.000
[password] => $2y$10$fyPLhL0KPcg26gyAaGtiAuyGGnmWcxadM7vlOJaRKmoetNri8lSbe
[job_name] => Software Developer
[job_title] => Junior Software dev
[bio] => This is my bio #test @bonga6367 http://www.helo.com
[music] => Hip Hop, House, RnB
[movies] => Rocky, fast and firious
[books] => our lady of benony, red blanket
[animals] => Dog, Cat, Elephant, horse, lion
[post_num] =>
[blocked] => 0
[closed] => 0
[online] => 1
[friendArray] => ,topollo57,siphe4573,nthethe5933,kabelo3088
)
)
)
) i only want suggestedUser, and count mutual friend or just suggestedUser will be fine.
Please help
Thanks in advance.
Here is the code that produced this data:
PHP Code: public function getUser($uid){ $this->db->where('user_id', $uid); $query = $this->db->get('users'); return $query->result_array(); }
public function getFriendSuggestions() { $userId = $this->session->userdata('user_id'); $friends = $this->getFriends($userId); $suggestedFriends = []; foreach ($friends as $friendId) { # Friends friends list. $ff_list = $this->getFriends($friendId); foreach ($ff_list as $ffriendId) { # If the friendsFriend(ff) is not us, and not our friend, he can be suggested if ($ffriendId != $userId && !in_array($ffriendId, $friends)) { # The key is the suggested friend $suggestedFriends[$ffriendId] = ['mutual_friends' => []]; $ff_friends = $this->getFriends($ffriendId); foreach ($ff_friends as $ff_friendId) { if (in_array($ff_friendId, $friends)) { # If he is a friend of the current user, he is a mutual friend $suggestedFriends[$ffriendId]['mutual_friends'][] = $ff_friendId; } } } } } # Convert the friend id's to user objects. $suggestedFriendObjs = array(); if (!empty($suggestedFriends)) { foreach ($suggestedFriends as $suggestedFriend => $mutualFriends) {
$suggestedFriendObj = new stdClass(); $suggestedFriendObj->suggestedUser = $this->getUser($suggestedFriend); if (!empty($mutualFriends)) { $mutualFriendObjs = []; foreach ($mutualFriends['mutual_friends'] as $mutualFriend) { $mutualFriendObjs[] = $this->getUser($mutualFriend); } } $suggestedFriendObj->mutualFriends = $mutualFriendObjs; $suggestedFriendObjs[] = $suggestedFriendObj; } } return $suggestedFriendObjs; }
}
|