2012-10-22 48 views
-1

我想從當前日期到下一年的當天取Facebook生日。 todate是364天后到現在m/d的日期。爲此,第一個fql將從jan檢索數據到當前日期,第二個是將數據從當前日期提取到31 dec。我想爲未來11個月和29天的即將到來的生日應用分頁。以下查詢正在工作並提取數據。任何人都可以告訴我這樣做的最佳方式。任何建議將不勝感激。facebook即將到來的生日只會在今年提取

$fromDate = date('m/d'); 
$past_birthdays = $facebook->api(array(
       'method' => 'fql.query', 
       'query' => "SELECT uid, name, birthday, birthday_date,substr(birthday_date,0,3) FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND birthday_date<'$toDate' AND birthday_date>='01/01' order by birthday_date", 
       'access_token' => $accessToken 
        )); 
if ($toDate > $fromDate) { 
      $condition = " AND birthday_date<'$toDate'"; 
     } else { 
      $condition = ""; 
     } 

$upcoming_birthdays = $facebook->api(array(
       'method' => 'fql.query', 
       'query' => "SELECT uid, name, birthday, birthday_date,substr(birthday_date,0,3) FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND birthday_date>='$fromDate' $condition order by birthday_date", 
       'access_token' => $accessToken 
        )); 

回答

1

在你的情況我在Facebook的API資源管理器檢查,如果你在你的查詢提供極限,那麼其在沒有一致的輸出,爲您解決問題的最好辦法是在陣列和顯示加載整個生日 列表它在插槽中。

$fromDate = date('m/d'); 
     $past_birthdays = ""; 
     $upcoming_birthdays = $facebook->api(array(
      'method' => 'fql.query', 
      'query' => "SELECT uid, name, birthday, birthday_date, substr(birthday_date, 0,3) from user where uid in (select uid2 from friend where uid1=me()) and birthday_date >='$fromDate' order by birthday_date Limit 0,500", 
      'access_token' => $accessToken 
       )); 
     $no = count($upcoming_birthdays); //exit; 
     if ($no < 500) { 
      $Limit2 = 500 - $no; 
      $past_birthdays = $facebook->api(array(
       'method' => 'fql.query', 
       'query' => "SELECT uid, name, birthday, birthday_date, substr(birthday_date, 0,3) from user where uid in (select uid2 from friend where uid1=me()) and birthday_date >='01/01' and birthday_date <= '$fromDate' order by birthday_date Limit 0,$Limit2", 
       'access_token' => $accessToken 
        )); 
      //echo count($past_birthdays);exit; 
      $upcoming_birthdays = array_merge($upcoming_birthdays, $past_birthdays); 

沒有必要採取TODATE因爲你是抓取,整個year.this CCODE僅500但全年運行查詢獲取。

相關問題