【问题标题】:two tables one for posts and other for friends connected to each other how to retrieve posts of friends两张表,一张放帖子,一张放朋友,互相连接如何检索朋友的帖子
【发布时间】:2015-04-27 06:58:22
【问题描述】:

我有两个表,第一个是帖子,其中有post_bypost coloumns,第二个是connectionstbl,其中有memberid 并与之连接,其中member 是登录用户,connectedWith是朋友

如何获取post_by=the connectedwith的post coloumn where的数据

以下查询:

$result=mysql_query("
        select
        social_posts.posted_by,
        social_posts.post as social_posts_post connectionstbl.connectedwith
        from 
        social_posts,connectionstbl
        where
        social_posts.posted_by = connectionstbl.connectedwith
        order by social_posts.p_id desc
");
while ($row =mysql_fetch_array($result))
{

    echo $row['social_posts_post']."<br/>";
}
?>

执行查询没有任何输出。

【问题讨论】:

  • 您能否正确格式化您的查询...
  • 请正确格式化您的查询并提供适当的表结构,以便我们为您提供帮助

标签: php mysql sql


【解决方案1】:

social_posts_post 和 connectiontbl.connectedwith 之间缺少逗号。我猜你的 error_reporting 或 display_errors 配置参数设置为不显示错误,否则你会看到警告。

【讨论】:

    【解决方案2】:

    你应该使用join:

    SELECT
        p.posted_by, p.post AS social_posts_post, c.connectedwith
    FROM social_posts p
    JOIN connectionstbl c ON p.posted_by = c.connectedwith
    ORDER BY p.p_id DESC
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多