a:2:{s:4:"body";a:1:{s:3:"und";a:1:{i:0;a:3:{s:5:"value";s:1319:"<?php

$type= 'country';
$countries=array();
$header = array();
$header[]='Competition';

$sum=array();
$result = db_query('SELECT * FROM {node} WHERE type = :type', array(':type' => $type));
foreach ($result as $record) {
  $countries[]=$record->nid;
   $header[]=$record->title;
   $sum[]=0;
}



$rows = array();


$competition= 'competition';
$result = db_query('SELECT * FROM {node} WHERE type = :type AND nid<>21', array(':type' => $competition));
foreach ($result as $record) {

   $p=array();

   for($i=0; $i<count($countries);$i++){
      $p[$i]=0;
      $result2 = db_query('select field_points_value as points from {field_data_field_points} where entity_id in (select entity_id from {field_data_field_country_ref} where field_country_ref_nid=:country_nid) AND entity_id in (select entity_id from {field_data_field_comp_ref} where field_comp_ref_nid=:competition_nid)',array(':country_nid'=>$countries[$i],':competition_nid'=>$record->nid));
      foreach ($result2 as $record2) {
         $p[$i]=$record2->points;
        $sum[$i]=$sum[$i]+$record2->points;
      }
   }

   $rows[] = array($record->title,$p[0],$p[1],$p[2],$p[3]);
}

     $rows[] = array('Sum:',$sum[0],$sum[1],$sum[2],$sum[3]);
echo theme('table', array('header' => $header, 'rows' => $rows));

?>";s:7:"summary";s:0:"";s:6:"format";s:8:"php_code";}}}s:17:"field_flickr_tags";a:0:{}}