PHP和MYSQL帮助

时间:2009-06-19 15:12:07

标签: php mysql

好的,这是我的php和mysql代码:

它是粗体,我想从在线表格中的uid,如果它在那里

where online.uid =''我需要所以它把uid放在那里。

$sql = ("select accounts.id, 
                accounts.tgid, 
                accounts.lastactivity, 
                cometchat_status.message, 
                cometchat_status.status, 
                **online.uid** 
         from friends_list join accounts 
                on friends_list.fid = accounts.id 
         left join cometchat_status 
                on accounts.id = cometchat_status.userid 
         where friends_list.status = '1' 
                and **online.uid = ''** 
                and friends_list.uid = '".mysql_real_escape_string($userid)."' 
         order by tgid asc");

1 个答案:

答案 0 :(得分:3)

@sledge在上面的评论中确定了问题(我不确定他为什么没有发表答案)。

您正在从online表格中选择一列,但未将其包含在FROM子句中。您必须从表中查询才能在查询的其他部分中引用其列。例如:

$sql = ("select accounts.id, 
            accounts.tgid, 
            accounts.lastactivity, 
            cometchat_status.message, 
            cometchat_status.status, 
            online.uid 
     from friends_list 
       join accounts on friends_list.fid = accounts.id 
       join online on ( ??? ) 
       left join cometchat_status 
            on accounts.id = cometchat_status.userid 
     where friends_list.status = '1' 
            and online.uid = '' 
            and friends_list.uid = '".mysql_real_escape_string($userid)."' 
     order by tgid asc");

您需要填写连接条件,因为原始帖子中没有足够的信息来推断online表与其他表的关系。

PS:使用mysql_real_escape_string()的赞誉。