サブスクライブテーブルからユーザーをフェッチする関数を作成しています。次に、これらのユーザーを使用して、個々の記事を取得し、順序付けられた方法で表示します。
私はそれを途中でやることができました。ユーザーを取得し、ユーザーの記事を出力します。ただし、一度に1人のユーザーが必要になります。サブスクライブテーブルですべてのユーザーを選択して取得する方法を探しているので、同時に表示できますが、日付順に表示できます。
テーブル :
**Subscribe :**
Lastviewed ( datetime )
Uniqueuser ( userid )
Subscription ( subscribed users id)
**Article:**
date_posted ( datetime )
uniqueuser ( users id)
これは私が得たものです:
$sesname = $_SESSION['full_name'];
$sesid = $_SESSION['user_id'];
connectDB();
$sql ="select * from subscribe where uniqueuser = '$sesid'";
$rsd = mysql_query($sql);
while ($row = mysql_fetch_array($rsd))
{
$subscription = $row['subscription'];
$lastviewed = $row['lastviewed'];
$substart = $row['substart'];
$sql3 = "select * from article
where uniqueuser = '$subscription'
and date_posted > '$lastviewed'
order by date_posted
desc limit 0, 7";
$rsd3 = mysql_query($sql3);
$newarticles = mysql_num_rows($rsd3);
while ($row3 = mysql_fetch_assoc($rsd3)) {
$id =$row3['id'];
$title = $row3['title'];
$uid = $row3['uniqueuser'];
$sql2 = "SELECT * FROM users WHERE id = '$uid'";
$result2 = mysql_query($sql2);
while ($row2 = mysql_fetch_assoc($result2)) {
$name = $row2['user_name'];
echo "<b><a>{$name}</a></b> wrote an <a>article</a><br>";
}
}
} //END SUBSCRIBE
これは以下を出力します:
User A wrote an article (1th july)
User A wrote an article (2th july)
User A wrote an article (3th july)
User A wrote an article (4th july)
User B wrote an article (1th july)
User B wrote an article (2th july)
User B wrote an article (3th july)
User B wrote an article (4th july)
ユーザーBの記事がユーザーAの投稿の間に投稿されている場合でも、ユーザーごとに注文します。
欲しい出力:
User A wrote an article (1th july)
User B wrote an article (1th july)
User A wrote an article (2th july)
User B wrote an article (2th july)
User A wrote an article (3th july)
User B wrote an article (3th july)
User A wrote an article (4th july)
User B wrote an article (4th july)
では、どのユーザーが書いたかに関係なく、どのようにまとめて日付順に並べ替えるのですか?私の問題は、サブスクライブクエリのwhileループが原因だと思いますが、これを行う他の方法はわかりません。どんな助けでも大歓迎です!=)