tags:

views:

108

answers:

1
+1  Q: 

PHP And MYSQ help

ok here is my php and mysql code:

where it is bold i wanted to the the uid from the online table and if it in there

where online.uid = '' i needed so it put the uid in there.

$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");
+3  A: 

@sledge identifies the problem in his comment above (I'm not sure why he didn't post an answer).

You are selecting a column from the online table, but you don't include it in your FROM clause. You have to query from a table in order to reference its columns in other parts of the query. For example:

$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");

You need to fill in the join condition, because there's not enough information in your original post to infer how the online table is related to other tables.

PS: Kudos for using mysql_real_escape_string().

Bill Karwin
The online table related to the accounts table
Gully