I'm currently working on a friendshipsystem. To accept a friend I need to get the friendship_id value.
Based on the email (from the session) I can get a lot of information, such as surname, name, photo, ID NUMBER,... from the specific friendshiprequest
I can print the information for each friendship in this way. So I have the FRIENDSHIP ID VALUE TO DISPLAY AS INFORMATION but now I want to use it in a function.
$friendrequests=$friendship->GetAllFriendRequests($email);
<?php
foreach ($friendrequests as $request) {
echo "
<div><p>
<a href='profile.php?user_id=".$request['friendship_applicant_id'] . "'>
<img src='uploads/" . $request['friendship_applicant_avatar'] . " " . " ' alt='' />" . $request['friendship_applicant_surname'] . $request['friendship_id'] . " " . $request['friendship_applicant_name'] . "
</a> has send you a friend request" . "
<form action='" . $_SERVER['REQUEST_URI'] . "' method='post'>
<button type='submit' name=''>Accept</button>
<button type='submit' name=''>Decline</button>
</form>
</p></div>";
}
?>
So i tried to get the specific number with the following code, but it says undefined index for friendship_id: $friendrequestnumber = $friendrequests['friendship_id'];
This is the code the GetAllFriendRequests function. Can I use this code or should I do it in a totally different way?
public function GetAllFriendRequests($email) {
$db = new Db();
$select = "SELECT * FROM friendship WHERE friendship_recipient = '" . $email . "' AND friendship_status = 'pending' ORDER BY friendship_id DESC";
$result = $db -> conn -> query($select);
$result_array=array();
while ($row = mysqli_fetch_array($result)) {
$result_array[]=$row;
}
return $result_array;
}
With a var_dump I get this information of the 2 requests:
Array ( [0] => Array ( [0] => 84 [friendship_id] => 84 [1] => ron@hot.com [friendship_applicant] => ron@hot.com [2] => 29 [friendship_applicant_id] => 29 [3] => ron [friendship_applicant_name] => ron [4] => ron [friendship_applicant_surname] => ron [5] => 1394134610fuckyou.jpg [friendship_applicant_avatar] => 1394134610fuckyou.jpg [6] => jan@hot.com [friendship_recipient] => jan@hot.com [7] => 1 [friendship_recipient_id] => 1 [8] => Vandenbergh [friendship_recipient_name] => Vandenbergh [9] => Jan [friendship_recipient_surname] => Jan [10] => 1394041001fuckyou.jpg [friendship_recipient_avatar] => 1394041001fuckyou.jpg [11] => Pending [friendship_status] => Pending [12] => 0000-00-00 00:00:00 [friendship_time] => 0000-00-00 00:00:00 ) [1] => Array ( [0] => 78 [friendship_id] => 78 [1] => Bert@hot.com [friendship_applicant] => Bert@hot.com [2] => 2 [friendship_applicant_id] => 2 [3] => Van Damme [friendship_applicant_name] => Van Damme [4] => Bert [friendship_applicant_surname] => Bert [5] => sdfds.png [friendship_applicant_avatar] => sdfds.png [6] => Jan@hot.com [friendship_recipient] => Jan@hot.com [7] => 1 [friendship_recipient_id] => 1 [8] => Vandenbergh [friendship_recipient_name] => Vandenbergh [9] => Jan [friendship_recipient_surname] => Jan [10] => 1394041001fuckyou.jpg [friendship_recipient_avatar] => 1394041001fuckyou.jpg [11] => Pending [friendship_status] => Pending [12] => 0000-00-00 00:00:00 [friendship_time] => 0000-00-00 00:00:00 ) )
Now he's updating but at the same time I get an error (Fatal error: Call to a member function fetch_assoc() on a non-object) at this line in my function AcceptFriendRequest:
'the return $data=$result->fetch_assoc();'
public function AcceptFriendRequest($requestnumber){ $db = new Db();
$select = "UPDATE friendship SET friendship_status = 'Accepted' WHERE
friendship_id ='" . $requestnumber . "'"; $result = $db->conn->query($select);
return $data=$result->fetch_assoc(); }