I am trying to put a post feed on the homepage but I am with difficulties on it. I think my query it might be wrong, but I want to pick the username from 'blabs' table and see if that 'username' from the same table is the user or the user's friends.
So to be clear, what I want is to add this 3 tables from db:
- users (to pick the profile picture, which is recorded as 'profile')
- blabs (to pick all the info from it: username, blabs and date)
- friends_request (to check if in 'blabs' table is their friends)
My php script for this content is:
<?php
if(isset($_SESSION['username']) === true) {
$friendFeed = "SELECT fr.username, u.profile, b.username
FROM (select from_username AS username,
username AS busername
FROM friends_request, blabs
WHERE to_username = '$user' AND accepted = 1
UNION ALL
SELECT to_username = '$user' AS username,
username AS busername
FROM friends_request, blabs
WHERE from_username = '$user' AND accepted = 1) AS fr
JOIN users AS u JOIN blabs AS b.username = fr.username";
$resultFeed = $sql->query($friendFeed);
if($resultFeed->num_rows == 0) {
echo "There are no posts from you or your friends.";
} else {
echo '<table>
<tr>';
while($rowFeed = mysqli_fetch_assoc($resultFeed)) {
$t1 = $rowFeed['username'];
$profile = $rowFeed['profile'];
$blab = $rowFeed['blab'];
if(!empty($profile)) {
$profileView = "<img src='".$profile."' width='auto' height='155px' />";
} else {
$profileView = "<img src='images/no-picture.png' width='auto' height='100px' />";
}
?>
<td>
<a href="profile.php?u=<?php echo $t1; ?>" class="no-style-friends">
<?php echo $profileView; ?><br />
</a>
</td>
<td>
<a href="profile.php?u=<?php echo $t1; ?>" class="no-style-friends">
<?php echo $t1; ?>
</a>
</td>
</tr>
<tr>
<td>
<?php echo $blab; ?>
</td>
</tr>
<?php
}
}
} else {
echo "<h3>Welcome to {WEBPAGE NAME}</h3>
<p>{Description}</p>";
}
?>
I want to do this so the user, when it's logged in can check his friend's posts and see what's new on it.