此查询返回特定事件的每个用户的性别(男性和女性)。
$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']}";
}
我做了两个函数:一个应该计算所有“男性”,其他变量应该计算所有“女性”变量。
$gender_female = count(explode('female', $getgender));
$gender_male = count(explode('male', $getgender));
但计数的结果出错了,因为做“男性”的计数,他也是,计算一个女性变量“(作为男性);
答案 0 :(得分:0)
尝试
$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
}
}