数据库:
代码:
$friends = $facebook->api('/me/friends');
$arr= $friends['data'];
$friend_ids_arr = array();
foreach($arr as $friend) {
$friend_ids_arr[] = $friend['id'];
}
$sql = "SELECT (SELECT * FROM xx_questions WHERE user_id IN (" . implode(',', $friend_ids_arr) . ") OR user_id = '$user' ORDER BY time DESC) (SELECT * from questions INNER JOIN users ON users.user_id = questions.user_id WHERE users.location = 'Cambridge, Cambridgeshire')";
$data = mysql_query($sql) or die(mysql_error());
while ($row = mysql_fetch_assoc($data)) {
// echo values from what's been selected
}
如果出现以下三种情况,我试图从xx_questions
(用户发布)中选择问题:
我设法让1和2工作,但当我尝试引入3时出现问题,所以我的两个问题是:
提前致谢,如果您需要更多信息,请与我们联系。
答案 0 :(得分:2)
要获取所需信息,需要将xx_questions连接到xx_users。类似下面的内容会返回与以下三个条件中的任何一个匹配的问题:
select *
from xx_questions q join
xx_users u
on q.user_id = u.user_id
where q.user_id in (<implode(',', $friend_ids_arr)>) or
q.user_id = '$user' or
u.location = (select location from xx_users where USER_ID = $user)
我写的更像是SQL而不是字符串,因此更容易阅读。