ログインしているアカウント所有者がフォローしている人々からのすべての投稿を表示する効率的な方法を見つけようとしています。
次の 2 つのキー テーブルがあります。
1-投稿
テーブル名:posts
id
、account_name
、published, body
2-フォロー
テーブル名:follows
id
、account_name
、followed_name
フォローされているすべてのアカウントからのすべての投稿を表示できる方法を見つけようとしています。投稿とフォローの間の接続はAccount_name
.
おそらく結合になることは理解していますが、それがWHERE
句の作成方法です。これまでのところ、次のものがあります (アカウント名は $_SESSION['account_name'] で設定されます):
$sql = "SELECT * FROM posts LEFT JOIN follows ON posts.account_name = follows.account_name WHERE --- How would I only get the posts from the accounts being followed ?---"
これは単純なことで、頭が疲れ果ててうまくいかないようです。
PDOでUPDATEを試みています
現時点では NULL を返し、
$sql = "SELECT * FROM share_posts WHERE account_name IN (SELECT followed_name FROM $this->account_follows WHERE account_name = :account_name)";
return $this->AC->Database->select($sql, array('account_name' => $account_name));
私のデータベースクラスに行きます:
public function select($sql, $array = array(), $fetch_mode = PDO::FETCH_ASSOC)
{
$stmt = $this->AC->PDO->prepare($sql);
foreach ($array as $key => $value)
{
$stmt->bindValue("$key", $value);
}
$stmt->execute();
return $stmt->fetchALL($fetch_mode);
}
ログインしているアカウントが他のアカウントをフォローしていても、返されるデータは現時点では NULL です。