2012-05-21 66 views
0

我在這裏有此代碼,它允許我提取喜歡特定頁面的朋友,但我需要提取不喜歡某個頁面的朋友。使用JOIN參數轉換fql查詢sql

下面是代碼:

$users = $facebook->api(array('method' => 'fql.query', 
        'query' => "SELECT uid, first_name, pic_small FROM user WHERE uid IN(
    SELECT uid FROM page_fan WHERE page_id='411133928921438' AND uid IN (
        SELECT uid2 FROM friend WHERE uid1 = me() 
   ))")); 

我應該怎樣使用OUTER來得到這樣的加入或SMTH:

$users = $facebook->api(array('method' => 'fql.query', 
      'query' => "SELECT uid, first_name, pic_small FROM user WHERE uid NOT IN(
     SELECT uid FROM page_fan WHERE page_id='411133928921438' AND uid IN (
      SELECT uid2 FROM friend WHERE uid1 = me() 
     ))")); 

回答

0

看到它不支持或OUTER JOIN NOT IN ,嘗試這樣做(不知道這是否是最好的方式,但它應該工作)

$likes = $facebook->api(array('method' => 'fql.query', 
    'query' => "SELECT uid, first_name, pic_small FROM user WHERE uid IN(
SELECT uid FROM page_fan WHERE page_id='411133928921438' AND uid IN (
    SELECT uid2 FROM friend WHERE uid1 = me() 
))")); 

$allfriends = $facebook->api(array('method' => 'fql.query', 
    'query' => "SELECT uid, first_name, pic_small FROM user WHERE uid IN (
    SELECT uid2 FROM friend WHERE uid1 = me() 
)")); 

// Loop through the rows 
// I think there is a page where you can test FQL at developers.facebook.com, I'll see if I can find it on my phone so I can see what the JSON response looks like and fix this code, in the mean while see if this works 

// Yeah so the code does this: 
// Loop through each item in the $allfriends result, (put the contents of the row into the $friend variable 
foreach($allfriends as $friend) 
{ 
    // This bit I need to change, this is supposed to look in the $likes array to see if the UID is present, but it will be comparing the uid against the whole object - need to tweak this 
    if(!in_array($friend['uid'], $likes)) 
    { 
     // Each friend that doesn't like the page should hit this part of the loop 
     echo $friend['uid']; 
    }     
} 

聲明 - 這是自從我使用PHP大約5年後,我已經觸摸了FQL的年齡 - 讓我知道是否有任何工作/不工作(我會很驚訝,如果它:D)

+0

謝謝你的答案...是的,我知道在FQL中沒有外連接,但我認爲我可以通過外連接達到此目的... 哎但faebook不允許NOT IN參數.. –

+0

好的 - 我明白了,沒有知道它不支持不在 - 不知道如果你可以做到這一點 - 你可能需要選擇它們,並過濾你想用軟件... – Charleh

+0

你能告訴我我該怎麼做嗎? ?通過PHP或什麼? –