php – sql帮助从所有粉丝获取数据? (如果我们关注,请推特)
发布时间:2020-12-13 22:28:50 所属栏目:PHP教程 来源:网络整理
导读:例如,如果我有 follow tablecompany one ( cid = 1 ) following two ( cid = 2 )company one ( cid = 1 ) following three( cid = 3 )feeds tablecompany one ( cid = 1 ) type 'product' description 'hello ive updated a product';company two ( cid = 2
例如,如果我有
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.description(例如这里的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,$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 或者更简单的从每个跟随获取feeds.description.following(cid = 1,3等)来自我. (cid = 1) 编辑* 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)所遵循的所有公司. 编辑:供稿应该包括我公司正在关注的公司供稿. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |