I’ve create a table of “followers” where users can follow other users. It’s set up as such:
ID username followname
username is the name of the person that is doing the action/following and followname is the person who is being followed.
I want to set up a news feed for each user on the profile.php page. The news feed should look at who the user is following (followname) and then fill the news feed with all the posts from those people in order of what time they were posted. The posts are in a different table called “needs” and each post is timestamped.
It’s barbaric but this is the code that I have so far:
[php]$following = mysql_query(“SELECT * FROM follow WHERE username=’$username’”);
while ($followrow = mysql_fetch_array($following)) {
$followname = $followrow[‘followname’];
$lookupposts = mysql_query (“SELECT * FROM needs WHERE needsusername=’$followname’”);
while ($postrow = mysql_fetch_array($lookupposts)) {
$description = $postrow[‘description’];
$needsusername = $postrow[‘needsusername’];
$datesubmitted = $postrow[‘datesubmitted’];
echo “User: $needsusername
Description:
$description
Date Submitted: $datesubmitted
----------------------------------------
”;
}
}[/php]
It works but there’s one problem. Instead of showing the posts by the timestamp only in the “needs” table it’s showing it by username THEN timestamp.
I know it’s because I have two while loops but I’ve been at this for hours and I really need some help figuring out how to get this working.
Thanks in advance!