我是初学者在sql soo我有一个很大的问题,这个“大”选择朋友表在cometchat。有人可以为我写。
Cometchat配置为朋友表:
friends
toid fromid
id 2 1
id 1 2
和sql选择它:
$sql = ("select DISTINCT ".TABLE_PREFIX.DB_USERTABLE.".".DB_USERTABLE_USERID." userid, ".TABLE_PREFIX.DB_USERTABLE.".".DB_USERTABLE_NAME." username,
".TABLE_PREFIX.DB_USERTABLE.".".DB_USERTABLE_LASTACTIVITY." lastactivity,
".DB_AVATARFIELD." avatar, ".TABLE_PREFIX.DB_USERTABLE.".".DB_USERTABLE_USERID." link,
cometchat_status.message, cometchat_status.status
from ".TABLE_PREFIX."friends join ".TABLE_PREFIX.DB_USERTABLE." on ".TABLE_PREFIX."friends.toid = ".TABLE_PREFIX.DB_USERTABLE.".".DB_USERTABLE_USERID." left join cometchat_status on ".TABLE_PREFIX.DB_USERTABLE.".".DB_USERTABLE_USERID." = cometchat_status.userid ".DB_AVATARTABLE."
where ".TABLE_PREFIX."friends.fromid = '".mysql_real_escape_string($userid)."' order by username asc");
return &sql;
我的Rails应用程序有友情表:
friendships
user_id friend_id
id 1 2
id 2 1
当我改变订单时,它不起作用。我认为现在这对我来说很难。在rails中我只是检查哪个友情有我的个人资料的user_id,并将它显示为friend_is为朋友。
这是使用朋友表生成标准的Cometchat设置的SQL:
select DISTINCT users.id userid,
users.name username,
users.current_sign_in_at lastactivity,
users.id avatar,
users.id link,
cometchat_status.message,
cometchat_status.status
from friends
join users on friends.toid = users.id
left join cometchat_status on users.id = cometchat_status.userid
where friends.fromid = '10'
order by username asc
我尝试将桌面从朋友更改为我的fiendships和toid(在friend_id上)和formid(在user_id上),反之亦然,但它仍然无法正常工作,我也没有得到朋友列表。