<?
$CELLPADDING=10;
$CELLSPACING=2;

$TABLEBGCOLOUR=`#FFFFF0`;

$mon = array(1,2,3,4,5,6,7,8,9,10,11,12);
$moa = array(`January`,`February`,`March`,`April`,`May`,`June`, `July`,`August`,`September`,`October`,`November`,`December`);

$month = date(~m~,strtotime(NOW())) - 1;
if ($month<1) $month=12;

echo `<center><br><table border=1 bgcolor=#ffd9b3 cellpadding=10 cellspacing=1><tr><td><table border=0 bgcolor=#fffeff cellspacing=10><tr><td>`;

echo `<center><h2> `,NOW(),`  <p>`;

//echo `Households<br> `;

ExecuteSQL(~create temporary table hh as select MONTHNAME(rValue) as Month, count(*) as Number
 from Responses where ProjectId=32 and qID=`TEFAPdate` and MONTHNAME(rValue)<>`` and isDeleted=0 group by MONTHNAME(rValue) union select `<b>All</b>` as Month, concat(`<b>`,count(*),`</b>`) as Number
 from Responses where ProjectId=32 and qID=`TEFAPdate` and MONTHNAME(rValue)<>`` and isDeleted=0~);

ExecuteSQL(~create temporary table b as select CaseID, rInstance, MONTHNAME(rValue) as Month from Responses where ProjectId=32 and qID=`TEFAPdate` and MONTHNAME(rValue)<>`` and isDeleted=0~);

ExecuteSQL(~create temporary table c as select * from b~);

//echo `<p>Individuals<br> `;

ExecuteSQL(~create temporary table ii as select Month, sum(rValue) as Number from Responses, b where ProjectId=32 and qID=`TEFAPHHsize` and isDeleted=0 and b.CaseID=Responses.CaseID and b.rInstance=Responses.rInstance group by Month union select `<b>All</b>` as Month, concat(`<b>`,sum(rValue),`</b>`) as Number from Responses, c where ProjectId=32 and qID=`TEFAPHHsize` and isDeleted=0 and c.CaseID=Responses.CaseID and c.rInstance=Responses.rInstance~);

ShowQueryResult(~select hh.Month as Month, hh.Number as Households, ii.Number as Individuals from hh, ii where hh.Month=ii.Month~);

echo `</h2></center>`;

echo `</td></tr></table></td></tr></table></center>`;


?>