好的,这是我的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");
答案 0 :(得分:3)
您正在从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()
的赞誉。