ユーザーの友人の投稿をエコーアウトしようとしています。基本的に、ログイン時の facebook のメイン ページに似たシステムです。現在、そのユーザーの友人の投稿をエコーする場合、そのユーザーのデータベース テーブルには、テキスト ファイルへのアドレスがあります。この場合、私のコンテンツは次のとおりです。1,3
数字は私の友人のユーザー ID です。次に、友人の投稿をエコーアウトしたいページは次のとおりです。
<?php
//echo $user_data['friend_list'];
$file = $user_data['friend_list'];
if($file != null)
{
$myFile = $file;
$fh = fopen($myFile, 'r');
$theData = fgets($fh);
fclose($fh);
//echo $theData;
$friend = explode(',', $theData);
//echo "This is friend array size ".count($friend)."</br>";
for($i=0; $i < count($friend); $i++)
{
if($i >= 0)
{
echo "I'm friend ".$i." and I have the User ID ".$friend[$i]."</br>";
$result = mysql_query("SELECT * FROM posts WHERE user_id = $friend[$i] ORDER BY timestamp");
while($row = mysql_fetch_array($result))
{
$user_id = $row['user_id'];
echo $row['content'] . " " . username_from_user_id($user_id) . " said on ".$row['timestamp'];
echo "<br />";
}
echo "<br/>";
}
}
}
?>
現在、これを返します/エコーします:
I'm friend 0 and I have the User ID 1
Hey, this is the first post. Well, I hope you like this network! harrison said on 2013-03-25 22:50:52
Hey, this is the second post ever on this website. I am testing out retrieving text from a database! harrison said on 2013-03-25 22:52:52
I really like the post system so far! harrison said on 2013-03-25 22:57:52
Okay, so far on user's profiles, it shows the six latest posts. harrison said on 2013-03-25 23:06:55
Hey Chinzo! harrison said on 2013-04-13 17:11:46
I'm friend 1 and I have the User ID 3
Hey! matt said on 2013-03-29 00:07:05
haha matt said on 2013-03-29 01:31:12
タイムスタンプ順にすべての投稿をエコーアウトするにはどうすればよいですか? 現在、各ユーザーの投稿を個別に並べ替えていますが、両方のユーザーからのすべての投稿をまとめて並べ替えているわけではありません1 and 3
。どうすればこれを行うことができますか?