使用 FQL 和 HTML 的 Facebook PHP SDK 生日应用程序
我使用 FQL 查询来获取用户朋友的生日。但我想根据月份和日期对用户进行排序,这样给定月份的所有生日都必须位于一个 div 中,该 div 的 id 是月份名称中的前 3 个字母,因为我使用 JS 显示/隐藏月份。这是可以实现的吗?
到目前为止的代码..
$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);
I use a FQL query to get birthdays of user's friends. But I want to sort the users according to month and day, such that all birthdays in a given month must be in a div whose id is the 1st 3 letters in the name of the month as I use JS to show/hide months. Is this achievable?
Code so far..
$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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想我明白你想要什么。为什么不创建一个月份数组来构建 div,然后在该 div 中显示该月生日的用户......
I think I understand what you want. Why not create an array of months to build the divs then display the users with birthdays in that month within that div...