我需要配置用户的Feed,以显示第一位用户关注的用户发布的帖子。
喜欢Instagram feed。我有一个posts
表。有author_id
列。在API请求中,我们有requester_id
POST参数。
我们有第二个名为relations
的表(以下是关注者)。
只有两列 - follow_by
和follow_to
。
使用PHP的SQL请求后,如何通过用户requester
获取帖子。
这意味着relations
必须是follow_to = author_id(from post)
和follow_by = requester_id
的行。
对不起有些错误(英文)。
感谢。
答案 0 :(得分:0)
我认为你应该执行子查询:
<?php
if($sq = $mysql_connection->query('SELECT `follow_by` following, `follow_to` followers, `author_id` id FROM `relations` WHERE `author_id`=(SELECT `author_id` FROM `posts`)')){
if($sq->num_rows){
while($row = $sq->fetch_object()){
// each row now has the following attributes within the loop
// $row->following // $row->followers // $row->id
}
}
$sq->free();
}
$mysql_connection->close();
?>
当然,如果您使用客户端信息来处理MySQL查询,那么您将要准备好您的语句。