Facebook PHP SDK生日APP使用FQL和HTML(Facebook PHP SDK Birthday APP using FQL and HTML)
我使用FQL查询来获取用户朋友的生日。 但我想根据月份和日期对用户进行排序,这样一个月内的所有生日必须在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);
原文:https://stackoverflow.com/questions/5610749
最满意答案
看看trait Dynamic,它将在Scala 2.10上提供(它在Scala 2.9上实验)。
例如:
scala> :paste // Entering paste mode (ctrl-D to finish) case class User(name: String) extends Dynamic { def applyDynamic(relationship: String)(to: User) = Relation(relationship, this, to) } case class Relation(kind: String, from: User, to: User) // Exiting paste mode, now interpreting. defined class User defined class Relation scala> User("john") friendsWith User("mary") res0: Relation = Relation(friendsWith,User(john),User(mary))
Look at trait Dynamic, which will be available on Scala 2.10 (it's experimental on Scala 2.9).
For example:
scala> :paste // Entering paste mode (ctrl-D to finish) case class User(name: String) extends Dynamic { def applyDynamic(relationship: String)(to: User) = Relation(relationship, this, to) } case class Relation(kind: String, from: User, to: User) // Exiting paste mode, now interpreting. defined class User defined class Relation scala> User("john") friendsWith User("mary") res0: Relation = Relation(friendsWith,User(john),User(mary))
相关问答
更多-
<:< 不是操作员 - 它是一个标识符 ,因此是下列之一: 一个类型的名字(类,特质,类型别名等) 方法的名称/ val或var 在这种情况下, <:<在库中出现两次,一次在Predef作为类出现,一次作为Manifest的方法出现。 对于Manifest上的方法,它检查由此清单表示的类型是否是清单参数表示的类型的子类型。 对于Predef中的这种类型,这是相对较新的,我也对它略有困惑,因为它似乎是同一声明的三部分组成部分! class <%<[-From, +To] extends (From) ⇒ To ...
-
Scala中的管道运算符(pipeline operator in Scala)[2022-01-18]
有几个选择。 一种是直接创建函数。 它只是略显凌乱。 x |> (z=>f(z,2)) |> (z=>g(z,3)) 另一种方法是创建可以折叠现有函数的arity的快捷方法。 一般来说它是很多样板,但第一个很容易: implicit class RichPipes[Y](y: Y) { def |>[Z](f: Y => Z) = f(y) def &>[X, Z](f: (X, Y) => Z): (X => Z) = (x: X) => f(x, y) } 然后你可以内联注入其他参数(利用& ... -
Scala中的通用运算符(Generic Operator in Scala)[2022-05-20]
看看trait Dynamic,它将在Scala 2.10上提供(它在Scala 2.9上实验)。 例如: scala> :paste // Entering paste mode (ctrl-D to finish) case class User(name: String) extends Dynamic { def applyDynamic(relationship: String)(to: User) = Relation(relationship, this, to) } case ... -
Scala中的运算符优先级(Operator precedence in Scala)[2024-01-10]
运算符优先级在运算符的第一个字符的Scala Reference - 6.12.3 Infix操作中得到修复。 以递增的顺序列出: (all letters) | ^ & = ! < > : + - * / % (all other special characters) 而且它不会很可能会改变。 它可能会产生比修复更多的问题。 如果您使用正常的运算符优先级更改一个类将是相当混乱。 Operator precedence is fixed in the Scala Reference - 6.12.3 I ... -
从规格: 6.12.3 InfixOperations中缀操作符可以是任意的标识符。 Infix操作符的优先级和关联性定义如下。 ... 运算符的关联性由运算符的最后一个字符决定。 以冒号“:”结尾的运算符是正确的关联。 所有其他运营商是左联。 在通过编译器的“typer”阶段打印程序后,您可以随时查看这些规则在Scala中的应用: scala -Xprint:typer -e "1 :: Nil" val r: List[Int] = {
val x$1: Int = 1; ... -
++运算符在Scala中(Increment (++) operator in Scala)[2022-02-07]
我的猜测是这样被忽略,因为它只适用于可变变量,对于不可变值来说这是不合适的。 也许决定++运算符不会尖叫分配,所以包括它可能会导致错误,你是否变异变量。 我觉得像这样的事情是安全的(一行): i++ 但这是一个不好的做法(用任何语言): var x = i++ 你不想混合赋值语句和副作用/突变。 My guess is this was omitted because it would only work for mutable variables, and it would not make sens ... -
为了解释它,我们首先要解释Scala中的嵌套类。 考虑这个简单的例子: class A { class B def f(b: B) = println("Got my B!") } 现在让我们尝试一下: scala> val a1 = new A a1: A = A@2fa8ecf4 scala> val a2 = new A a2: A = A@4bed4c8 scala> a2.f(new a1.B)
:11: error: type mismatch; found ... -
Scala @运算符(Scala @ operator)[2023-06-14]
它可以将匹配的模式绑定到变量。 请考虑以下内容,例如: val o: Option[Int] = Some(2) 您可以轻松地提取内容: o match { case Some(x) => println(x) case None => } 但是如果你不想要Some的内容 ,而是选项本身呢? 这将通过以下方式实现: o match { case x @ Some(_) => println(x) case None => } 请注意, @可以在任何级别使用,而不仅仅是匹配的顶级。 It ... -
++运算符不是强制性的增量运算符,而是作为两个集合的联合,以便产生新的集合而不是修改任何一个旧集合。 The ++ operator is not meant as an imperative increment operator, but as a union of two collection, such that it produces new collections instead of modifying either of the old ones.
-
“=>”运算符在Scala中(“=>” operator in Scala)[2022-06-15]
它通过名称传递参数。 意味着当访问参数时将评估表达式。 it's passing parameter by name. means expression will be evaluated when parameter is accessed.