【问题标题】:FQL PHP COUNT male and female from variableFQL PHP COUNT 来自变量的男性和女性
【发布时间】:2014-03-04 12:59:34
【问题描述】:

此查询返回特定事件的每个用户的性别(男性和女性)。

$fql = "select uid, sex from user where uid in (SELECT uid FROM event_member WHERE eid = $festaid AND rsvp_status = 'attending' AND start_time >= now() ORDER BY start_time desc) LIMIT 5000";  

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

$fqlResult   =   $facebook->api($param);

//looping through retrieved data

$getgender = '';
foreach( $fqlResult as $keys => $values ){

    $start_date = date( 'l, F d, Y', $values['start_time'] );
    $start_time = date( 'g:i a', $values['start_time'] );

    //printing the data
  $getgender .= "{$values['sex']}";   
}

我做了 2 个函数:一个应该计算所有“男性”变量,其他变量应该计算所有“女性”变量。

$gender_female = count(explode('female', $getgender));
$gender_male = count(explode('male', $getgender));

但是计数的结果出错了,因为在做“男性”的计数时,他也算了一块女性变量“(作为男性);

【问题讨论】:

    标签: php count facebook-fql explode fql.multiquery


    【解决方案1】:

    试试

    $getgender = '';
    $femaleCount = 0;
    $maleCount = 0;
    foreach( $fqlResult as $keys => $values ){
    
        $start_date = date( 'l, F d, Y', $values['start_time'] );
        $start_time = date( 'g:i a', $values['start_time'] );
    
        //printing the data
        $getgender .= "{$values['sex']}";   
        if($values['sex']=="female"){
           $femaleCount++; //Female Count
        }else{
           $maleCount++; // Male Count
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2016-09-02
      • 2013-06-11
      • 2020-05-13
      • 1970-01-01
      • 1970-01-01
      • 2017-10-08
      • 2013-09-01
      • 1970-01-01
      • 2021-01-13
      相关资源
      最近更新 更多