使用 FQL 和 HTML 的 Facebook PHP SDK 生日应用程序

发布于 2024-10-31 13:17:26 字数 1188 浏览 0 评论 0原文

我使用 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);

感谢 andrewdavid 到目前为止对我的帮助:)

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);

Thanks to andrew and david for helping me this far:)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

⊕婉儿 2024-11-07 13:17:26

我想我明白你想要什么。为什么不创建一个月份数组来构建 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>
<?  
}
?>

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...

<?
$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>
<?  
}
?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文