//*********************************
$Active=0;
$Sql ="SELECT distinct pagerno FROM tbldetails
WHERE ccode = '$StrCode'
AND col1 <> 'invalid'
AND col6 <= '$strDte'
AND edate <= '$strDte'";

$rst = mysql_query($Sql, $Obj->create());
while($rowPgr = mysql_fetch_assoc($rst)) {

$SqlSub ="SELECT col5 FROM tbldetails
WHERE ccode = '$StrCode'
AND pagerno = '$rowPgr[pagerno]'
AND col1 <> 'invalid'
AND col6 <= '$strDte'
AND edate <= '$strDte'
order by detailid desc limit 0,1";

$rstSub = mysql_query($SqlSub, $Obj->create());
while($rowCol = mysql_fetch_assoc($rstSub)) {
if ($rowCol['col5']=="1"){
$Active+=1;
}
}
mysql_free_result($rstSub);

}
mysql_free_result($rst);
mysql_close($Obj->create());