Sql help get data from all followers? (e.g. twitter if we follow)

alt text

For example, if I have

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'; 

question

how can i get all feeds.description from the company that my company is (example here is cid = 1)?

heres my simple pdo sql to get just mine.

  $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 

maybe something like this? (failure)

  $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 

or easier to get feeds.description from each subsequent. The following (cid = 1,2,3, etc.) is from me. (cid = 1) or if Twitter gets the status of my friends (the friends I follow)

change *

some good guys from irc mysql said use connections. but i just don't get it. i get it

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

then

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

Can anyone give me an example of integrating into this problem?

+4
source share
1 answer

So, if we assume that the question arises: "How do I get all the feed information from the company that my company does?" you want to join using the following key:

 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; 

This list should include all the companies for which your: cid (1).

EDIT: Channels must include my company feeds + feeds that my company monitors.

+1
source

All Articles