Search code examples
phpfacebooksumfacebook-fqlphotos

Sum of integers returned fql


This is my first post and I'm fairly new to php, mysql, and developing for facebook.

I'm having the worst time with this normally I would use the sum with the sql request but fql doesn't seem to support that. I'm trying the query the albums which works as expected, but I only want to echo the number of total photos/videos. I'm sure the solution is there I'm just not seeing it clearly.

===================================================

Currently I'm getting these results returned;

Album#1 = 50

Album#2 = 10

Album#3 = 25

etc.


I just want to add those #'s returned together.

===================================================

    try {
        $me = $facebook->api('/me');
        $fql    =   "SELECT photo_count, video_count FROM album WHERE owner=me()";
        $param  =   array(
                          'method'    => 'fql.query',
                          'query'     => $fql,
                          'callback'  => ''
                          );
        $fqlResult   =   $facebook->api($param);
        foreach($fqlResult as $row){
            echo "<br><br />";
            echo $row['photo_count'];               
        }

    } catch (FacebookApiException $e) {
        error_log($e);
    }

=======================================================

Your help is appreciated.


Solution

  •   try {
            $me = $facebook->api('/me');
            $fql    =   "SELECT photo_count, video_count FROM album WHERE owner=me()";
            $param  =   array(
                              'method'    => 'fql.query',
                              'query'     => $fql,
                              'callback'  => ''
                              );
            $fqlResult   =   $facebook->api($param);
            $asset_count = 0;
            foreach($fqlResult as $row){
                $asset_count += (int)$row['photo_count'] + (int)$row['video_count'];               
            }
            echo "<br/><br/>";
            echo $asset_count;
    
        } catch (FacebookApiException $e) {
            error_log($e);
        }