I am programming a chat room on my site but I am really new to php. I want users to be able to chat with the users that played in the same teams of a game (knowing that users can have participated together to differents team) and who work in the same area.
Assume there are three tables : the account user's table, the area's t able, games'table
I have a function that returns my query that looks like
function myfunction($userid){
$games_user=mysql_query('select theme from games where games.userid="'.$userid.'"');
$games_theme = mysql_fetch_array($games_user);
$sql = ("select userid, username, area.userid
from account
left join area
on account.userid = area.userid
left join games
on account.userid = games.userid
where account.userid <> '".mysql_real_escape_string($userid)."' and '".(in_array(games.theme,$games_theme))."' and area.userid=1
);
return $sql;
}
Reformatted:
$sql = "
SELECT userid, username, area.userid
FROM account
LEFT JOIN area ON account.userid = area.userid
LEFT JOIN games ON account.userid = games.userid
WHERE account.userid <> '".mysql_real_escape_string($userid)."'
AND '".(in_array(games.theme,$games_theme))."'
AND area.userid = 1
";
But it really doesn't work, I think I have syntax problems. I don't really understand how in_array is indexed, and I don't know how to do in a simpler way that query
Can anybody help ?