0

数据库:

  • 表 #1: xx_users (id, name, user_id, location, network)
  • 表 #2: xx_questions (id, user_id, time)

代码:

$friends = $facebook->api('/me/friends');
$arr = $friends['data'];
$friend_ids_arr = array();
foreach($arr as $friend) {
    $friend_ids_arr[] = $friend['id'];
}

$sql = "SELECT q.*, u.location, u.network
            FROM xx_questions q 
            JOIN xx_users u 
            ON q.user_id = u.user_id
            AND (q.user_id = $user) OR
            q.user_id IN (".implode(',', $friend_ids_arr).") OR
            u.location = (SELECT location FROM xx_users WHERE user_id = $user) OR
            u.network = (SELECT network FROM xx_users WHERE user_id = $user)
            ORDER BY q.time DESC";

$data = mysql_query($sql) or die(mysql_error());

while ($row = mysql_fetch_assoc($data)) {

if ($row['anon'] == 1) {
    $asker = "<span style='color: #333;'>Anonymous</span>";
}

else {
    $asker_name = json_decode(file_get_contents("http://graph.facebook.com/".$row['user_id']))->name;
    $asker = "<a href='user.php?id=".$row['user_id']."'><b>".$asker_name."</b></a>";
}

echo "<div class='question'>";
echo "<a href='q.php?id=".$row[id]."' class='left'>".$row['question']."</a><span style='color: #666'>&nbsp;";

$sql2 = "SELECT * FROM xx_answers WHERE question_id = '".$row[id]."'";
$result = mysql_query($sql2);
$xxx = mysql_num_rows($result);
echo "($xxx)";

echo "</span>";
echo "<div class='right'><span style='color: #999'>";

$to_time = strtotime("now");
$from_time = strtotime(".$row[time].");
$since = $to_time-$from_time;

time_since($since);

echo " by <a href='user.php?id=".$row['user_id']."'><b>".$asker."</b></a></span></div>";
echo "<div style='clear:both;'></div>";
echo "</div>";
}

我正在使用此代码来回显数据库中的三种问题:

  1. 用户与海报的 Facebook 好友在哪里
  2. 用户与发布者位于同一位置的位置
  3. 用户与发布者共享网络的位置

除了所有值都回显两次之外,这一切都很好。奇怪的是,当我只回显上述 3 个中的一个时,这些值只会按预期回显一次。知道为什么会这样吗?

4

0 回答 0