2

わかりました。2つのテーブルがあります。1つは名前付きaccount_membersで、もう1つは。という名前account_followsです。account_membersがお互いをフォローできるTwitterスタイルのフォローシステムが欲しいです。

Account Follows Table Structure:

id
account_name
followed_name
time

Account Members Table Structure:

id
Account_name
status (Account active or not)

たった1つの簡単なクエリで、フォローされているすべてのアカウントを取得できると思いました。

public function following($account_name)
{
    $sql = "SELECT 

    F.id, F.account_name, F.followed_name, F.time, 
    M.account_name AS session_name, M.status 

    FROM account_follows F
    LEFT JOIN account_members M ON F.account_name = M.account_name

    WHERE F.account_name = :account_name 
    AND M.account_name = :account_name

    ORDER BY id DESC LIMIT 5";
}

これにより、フォローされているすべてのaccount_membersが表示されます($account_nameURLを介して設定されます)

私が抱えている問題は、ログインしているaccount_memberが、フォローしている友達の友達をフォローまたはフォロー解除できるようにすることです。ログインしたaccount_memberを簡単にチェックして、リストにある人のフォローを解除するには、次の手順を実行します。

if($_SESSION['account_name'] == $row['account_name'])
{
    echo'<a href="" id="..." class="...">Unfollow</a>';
}

上記は問題なく動作しますが、ログインしているアカウントのフォロワーのフォロワーと同様のことをしたいのですが...それが理にかなっている場合はどうでしょうか。

したがって、ボブはログインし、ボブは自分のフォローリストを見てマイクをクリックし、マイクがフォローしている人を表示します。このリストから、マイクがフォローしている人(およびボブがフォローしている可能性のある人)をフォロー/フォロー解除することができます。

任意のヘルプやガイダンスをいただければ幸いです。

4

1 に答える 1

1

あなたが持っているクエリは、渡されたメンバーのアカウント名に対して機能しますが、クエリ自体は現在ログインしているメンバーのフォローを考慮していないため、それらのデータをそれに結合する必要があります.

クエリは、URL で指定されたアカウントがフォローしているメンバーのリストを返します。これにより、ログインしているユーザーもそのメンバーをフォローしているかどうかがわかります。そのビットを使用して、フォロー リンクまたはフォロー解除リンクをエコーする必要があるかどうかを決定します。

SELECT 
        theirFollows.id, theirFollows.account_name, 
        theirFollows.followed_name, theirFollows.time, 
        M.account_name AS member_name, M.status, 
        case 
            when myFollows.followed_name is null then 0
            else 1
        end as sessionMemberIsFollowing
FROM    account_members M
        LEFT JOIN account_follows theirFollows
          ON theirFollows.account_name = M.account_name
        LEFT JOIN 
            (
                select followed_name
                from account_follows 
                where account_name = :session_account_name
            ) myFollows
            on myFollows.followed_name = theirFollows.followed_name

WHERE   M.account_name = :account_name

選択した列の 1 つに session_name というラベルが付けられていましたが、渡された account_name は URL から取得されているため、少し誤解を招く可能性があります。また、それはあなたが参加している列であるため、句が必要な場所は1つだけです。

于 2013-03-19T13:27:51.017 に答える