2009-06-19 67 views
1

確定這裏是我的PHP和MySQL代碼:PHP和MYSQ幫助

它是大膽的我想從在線表格的UID,如果它在那裏

其中online.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"); 
+5

你沒有在任何地方引用在線表格。 – 2009-06-19 15:14:04

+2

但問題是什麼?我不明白。 – Timotei 2009-06-19 15:14:30

回答

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()的榮譽。