SQLは、すべてのフォロワーからデータを取得するのに役立ちますか? (フォローしている場合のTwitterのように)

StackOverflow https://stackoverflow.com/questions/3596798

  •  02-10-2019
  •  | 
  •  

質問

alt text

私が持っている場合の例

follow table
company one ( cid = 1 ) following two ( cid = 2 )
company one ( cid = 1 ) following three( cid = 3 )

feeds table
company one ( cid = 1 ) type 'product' description 'hello ive updated a product';
company two ( cid = 2 ) type 'product' description 'hello ive updated a product im from company 2';
company three ( cid = 3 ) type 'shoutout' description 'hello ive i got a shoutout im company 3';
company one ( cid = 1 ) type 'product' description 'hello ive updated my second product';

質問

会社からすべてのfeeds.desscriptionを入手するにはどうすればよいですか(例はcid = 1です)?

ここに私の単純なPDO SQLが私のものを手に入れるのです。

    $data['feeds']['cid'] = 1;

    return $this->db->fetchAll("SELECT feeds.type, feeds.$type, feeds.cid, feeds.time, companies.name FROM feeds, companies WHERE 
    feeds.cid = :cid AND companies.cid = :cid ORDER BY feeds.fid DESC LIMIT 0, 5", $data['feeds']);

this will display
hello ive updated a product
hello ive updated my second product

多分このようなもの? ( 不合格 )

    $data['feeds']['cid'] = 1,2,3;

    return $this->db->fetchAll("SELECT feeds.type, feeds.$type, feeds.cid, feeds.time, companies.name FROM feeds, companies WHERE 
    feeds.cid = :cid AND companies.cid = :cid ORDER BY feeds.fid DESC LIMIT 0, 5", $data['feeds']);

this should be displaying like
hello ive updated a product
hello ive updated a product im from company 2
hello ive i got a shoutout im company 3
hello ive updated my second product

または、私からの各follow.following(cid = 1,2,3など)のfeeds.descriptionをよりシンプルに取得します。 (cid = 1)またはTwitterが私の友達のすべてのステータスを取得した場合(私がフォローしている友達)

編集*

IRC MySQLの一部の善良な人は、参加を使用すると言っています。しかし、私はそれを手に入れません。私が得るのはこれです

fetch all the follow.following from cid = me ( example cid = 1 )

それから

SELECT * FROM feeds WHERE feeds.cid = IN (2,3,cid that im following ( see follow.following )) 

誰かが私にこの問題に参加する例を挙げることができますか?

役に立ちましたか?

解決

それで、質問が「私の会社がフォローしている会社からすべてのfeeds.descriptionを取得するにはどうすればよいですか?」次のキーを使用して参加したい:

select 
companies.name, 
feeds.type, 
feeds.description 
from follow 
inner join feeds on (follow.following = feeds.cid or follow.cid = feeds.cid)
inner join companies on (feeds.cid = companies.cid)
where follow.cid = :cid
order by feeds.fid desc 
limit 5;

これにより、cid(1)がフォローしているすべての企業がリストされるはずです。

編集: フィードには、私の会社のフィード +私の会社がフォローしているフィードを含める必要があります。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top