我有兩個表第一次被稱爲'帖子',第二個被稱爲'朋友' 我想獲得的帖子,它的'發佈者'列存在'朋友'表(這意味着要得到朋友的帖子)比我想要通過'posts'表中找到的日期時間列命令它。獲取用戶的朋友的帖子,並按colomns datetime排序
我曾嘗試是:
$fetch_fr_result = $conn->query("SELECT frid FROM friends WHERE username='$userusername'");
while ($fetch_fr_send = $fetch_fr_result->fetch(PDO::FETCH_OBJ)){
$fetch_fr_id = $fetch_fr_send->frid;
$fetch_fr_data_result = $conn->query("SELECT username FROM users WHERE id='$fetch_fr_id'");
$fetch_fr_data_send = $fetch_fr_data_result->fetch(PDO::FETCH_OBJ);
$fetch_fr_data_username = $fetch_fr_data_send->username;
$fetch_posts_result = $conn->query("SELECT * FROM posts WHERE publisher='$fetch_fr_data_username' ORDER BY orderdate DESC LIMIT 5");
while ($fetch_posts_send = $fetch_posts_result->fetch(PDO::FETCH_OBJ)){
$fetch_posts_msg = $fetch_posts_send->thetext;
$fetch_posts_time = $fetch_posts_send->time;
if (!empty($fetch_posts_msg)){
echo '<div class="posttext">' . $fetch_posts_msg . '</div> - ' . $fetch_posts_time;
}
}
}
在這段代碼的問題是: 獲取然後每個朋友得到朋友的帖子,然後按時間順序它們,但我想按時間排序的所有朋友的帖子!
請告訴我該怎麼做?
你能告訴我們你的表結構嗎?順便說一句,你想在這裏加入表格。 –
以下是表格圖片:http://imgur.com/4mFKkTM | http://imgur.com/GDHJfAI –
和用戶表請。 –