2011-04-10 15 views
0

我使用FQL查詢來獲取用戶朋友的生日。但我想根據月份和日期對用戶進行排序,以便給定月份中的所有生日必須位於其ID爲本月名稱中的前3個字母的div中,因爲我使用JS來顯示/隱藏月份。這是可以實現的嗎?使用FQL和HTML的Facebook PHP SDK生日APP

到目前爲止的代碼..

$query = "SELECT uid, first_name, last_name, birthday_date, sex, pic_square, current_location, hometown_location FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND strlen(birthday_date) != 0 ORDER BY birthday_date"; 

$prm = array(
     'method' => 'fql.query',  
     'query'  => $query, 
     'callback' => ''  
    ); 

$friends = $facebook->api($prm); 

$sort = array(); 
foreach($friends as $friend){ 
// note the extra 0's here, to give us padding to filter out duplicate array keys 
// this gives us an int in the format 030100, 093100, etc 
    $key = (int)date('Md00', strtotime($friend['birthday_date'])); 

// make sure we don't have duplicates...if the key already exists, incrememnt it by one 
    while(isset($sort[$key])) $key++; 
    $sort[$key] = $friend; 
} 
// sort the items by array key 
ksort($sort); 

感謝andrewdavid幫助我這個遠:)

+0

您可能需要改進您的問題或至少提供一些Javascript代碼才能看到確切地說你想如何使用它。 – 2011-11-16 23:35:21

回答

0

我想我明白你想要什麼。爲什麼不創建一個月的數組來構建div,然後在那個div內的當月顯示用戶的生日...

<? 
$months = array('jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec'); 

foreach($months as &$month){ 
?> 
    <div id="<?=$month?>"> 
    <? // loop through users with birthday in $month ?> 
    </div> 
<? 
} 
?> 
相關問題