我有很好的5-7张桌子。然后,我有一个单独的表,其中包含每个表内容的post_id
。现在,我想要一个类似于Facebook的用户馈送。那么,我如何加入提要表格,比如说照片、文章、视频。
结构:
// post_id _id=来自所有其他唯一表的内容
User Feed Table:
id
content_id
user_id
link
Posts:
id
post_id
post_content
tags
user_id
links:
id
post_id
link_content
tags
user_id
link_comments:
id
post_comment_id
post_id
tags
user_id
发布于 2011-06-16 23:26:38
您必须使用MYSQL JOIN语句。http://dev.mysql.com/doc/refman/5.1/en/join.html
发布于 2011-06-16 23:32:48
您可以使用join,也可以简单地说content_id = post_id ...在您不知道的情况下指定多个表的方式是这样的……
从提要f、帖子p、链接l、内容c中选择f.*,其中f.content_id = l.post_id等。等等。
发布于 2011-06-16 23:42:01
我建议在提要表格中为“type”添加一个额外的字段。这将是内容的类型。每次有人添加新帖子时,都会在提要表格中插入一条记录,并将content_id设置为该帖子的id和type=1 (1可能表示帖子)。然后,您可以像这样构造一个查询:
// get all records from feed
// then foreach record
// $type_id = feed->type
// then do a switch statement
switch($type_id){
case 1:
$type="articles";
break;
case 2:
$type="videos";
}
// then do another query joining the feed to the content
SELECT * FROM '$type'
JOIN feed ON '$type'.id = feed.content_id
WHERE '$type'.id = feed->content_id
//execute query and add to an array of feed items
//endforeach
我很抱歉我的语法都错了这更像是一个解决问题的答案...
https://stackoverflow.com/questions/6374295
复制相似问题