I am struggling to solve this problem for days, and I can't figure out how should I do this.
I am able to get my own posts and the friends posts if both user are friends.
I want to check whether the user is friend with each other, and if not, don't show the non-friends posts.
The problem:
When the user friend with a user it's normally shows the friend's posts as well. The main issue is when
Error message: Notice: Undefined offset:
Example:
If the admin is friend with devel
The outcome:
Shows the admin's and devel's posts to each other correctly
If Zorro is friend with admin
The outcome:
Zorro's posts will be display to admin correctly, but it display the posts to devel as well with an error message
Notice: Undefined offset:
If Zorro will become friend with devel
The error message will go away and will show Zorro's and Devel's posts to each other correctly.
The code to getting the posts.
Query:
$sql = "SELECT * FROM posts JOIN connections WHERE posts.author = '$currentUser' OR posts.author IN (SELECT FriendReferee FROM connections WHERE Friend ='$currentUser'
or content<>'') OR posts.author IN
(SELECT Friend FROM connections WHERE FriendReferee ='$currentUser'
or content<>'') ORDER BY postID DESC";
$result = $conn->query($sql);
Fetching the database:
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
The loop:
foreach($combine as $commentID => $imagesID) {
if ($postedBy[$commentID] == $currentUser) {
$profLink = '<a class="authorLink" href="../profile"><span class="author"><i class="fas fa-user-circle"></i> '.$postedBy[$commentID].'</span></a>';
} else {
$profLink = '<a class="authorLink" href="../view/?name='.$postedBy[$commentID].'"><span class="author">'.$postedBy[$commentID].'</span></a>';
}
echo $profLink;
echo $comments[$commentID];
if ($nameOfImage[$commentID] == NULL) {
echo "";
} else {
foreach($imgs[$commentID] as $img) { // foreach loop that will render all the images...
echo $img;
}
}
}
}
}
Aucun commentaire:
Enregistrer un commentaire