<?
function ttcatchdistrict($y,$m,$d)
{
	include "connect.inc.php";
	$sqltotalcatch = "SELECT sum(catchprimary) AS st FROM fishoperation INNER JOIN district ON district.disid = fishoperation.District";
	$sqltotalcatch = $sqltotalcatch. " WHERE year( SamplingDate )='$y' AND month( SamplingDate )='$m' AND district =$d GROUP BY month(SamplingDate)";
	//echo $sqltotalcatch;
	$qrytotalcatch = mysql_query($sqltotalcatch);
	$resgettotalcatch = mysql_fetch_array($qrytotalcatch);
	$sumcatch = $resgettotalcatch[st];
	return $sumcatch;
}
function ttcatchsamplingport($y,$m,$s)
{
	include "connect.inc.php";
	$sqltotalcatch = "SELECT sum(catchprimary) AS st FROM fishoperation INNER join fishingport on fishingport.portid = fishoperation.LandingPort";
	$sqltotalcatch = $sqltotalcatch. " WHERE year( SamplingDate )='$y' AND month( SamplingDate )='$m' AND LandingPort =$s GROUP BY month(SamplingDate)";
	//echo $sqltotalcatch;
	$qrytotalcatch = mysql_query($sqltotalcatch);
	$resgettotalcatch = mysql_fetch_array($qrytotalcatch);
	$sumcatch = $resgettotalcatch[st];
	return $sumcatch;
}
function ttcatchzone($y,$m,$z)
{
	include "connect.inc.php";
	$sqltotalcatch = "SELECT sum(catchprimary) AS st FROM fishoperation";
	$sqltotalcatch = $sqltotalcatch. " WHERE year( SamplingDate )='$y' AND month( SamplingDate )='$m' AND FishingZone ='$z' GROUP BY month(SamplingDate)";
	//echo $sqltotalcatch;
	$qrytotalcatch = mysql_query($sqltotalcatch);
	$resgettotalcatch = mysql_fetch_array($qrytotalcatch);
	$sumcatch = $resgettotalcatch[st];
	return $sumcatch;
}

function ttcatchgearandvessel($y,$m,$g,$v)
{
	include "connect.inc.php";
	$sqltotalcatch = "SELECT sum(catchprimary) AS st FROM fishoperation inner join gearandmethod on gearandmethod.fgid = fishoperation.ShipGearId";
	$sqltotalcatch = $sqltotalcatch. " WHERE year( SamplingDate )='$y' AND month( SamplingDate )='$m' AND fgid =$g and VesselId = '$v' GROUP BY month(SamplingDate)";
	//echo $sqltotalcatch;
	$qrytotalcatch = mysql_query($sqltotalcatch);
	$resgettotalcatch = mysql_fetch_array($qrytotalcatch);
	$sumcatch = $resgettotalcatch[st];
	return $sumcatch;
}

function ttcatchyear($y)
{
	include "connect.inc.php";
	$sqltotalcatchy = "SELECT sum(catchprimary) AS ttcy FROM fishoperation INNER JOIN district ON district.disid = fishoperation.District";
	$sqltotalcatchy = $sqltotalcatchy. " WHERE year( SamplingDate )='$y' GROUP BY year(SamplingDate)";
	//echo $sqltotalcatchy;
	$qrytotalcatchy = mysql_query($sqltotalcatchy);
	$resgettotalcatchy = mysql_fetch_array($qrytotalcatchy);
	$sumcatchy = $resgettotalcatchy[ttcy];
	return $sumcatchy;
}
function ttcatchyeargearvessel($y,$g,$v)
{
	include "connect.inc.php";
	$sqltotalcatchgv = "SELECT sum(catchprimary) AS ttgv FROM fishoperation inner join gearandmethod on gearandmethod.fgid = fishoperation.ShipGearId";
	$sqltotalcatchgv = $sqltotalcatchgv. " WHERE year( SamplingDate )='$y' and ShipGearId = $g and VesselId = '$v' GROUP BY year(SamplingDate)";
	//echo $sqltotalcatchgv;
	$qrytotalcatchgv = mysql_query($sqltotalcatchgv);
	$resgettotalcatchgv = mysql_fetch_array($qrytotalcatchgv);
	$sumcatchgv = $resgettotalcatchgv[ttgv];
	return $sumcatchgv;
}
function ttcatchyeargear($y,$g)
{
	include "connect.inc.php";
	$sqltotalcatchg = "SELECT sum(catchprimary) AS ttg FROM fishoperation inner join gearandmethod on gearandmethod.fgid = fishoperation.ShipGearId";
	$sqltotalcatchg = $sqltotalcatchg. " WHERE year( SamplingDate )='$y' and ShipGearId = $g GROUP BY year(SamplingDate)";
	//echo $sqltotalcatchg;
	$qrytotalcatchg = mysql_query($sqltotalcatchg);
	$resgettotalcatchg = mysql_fetch_array($qrytotalcatchg);
	$sumcatchg = $resgettotalcatchg[ttg];
	return $sumcatchg;
}
function ttnoofdays($y,$m,$g,$v)
{
	include "connect.inc.php";
	$sqltotaldays = "SELECT sum(duration) AS nd FROM fishoperation inner join gearandmethod on gearandmethod.fgid = fishoperation.ShipGearId";
	$sqltotaldays = $sqltotaldays. " WHERE year( SamplingDate )='$y' AND month( SamplingDate )='$m' AND ShipGearId =$g and VesselId = '$v' GROUP BY month(SamplingDate)";
	//echo $sqltotalcatch;
	$qrytotaldays = mysql_query($sqltotaldays);
	$resgettotaldays = mysql_fetch_array($qrytotaldays);
	$sumdays = $resgettotaldays[nd];
	return $sumdays;
}
function ttdayyearvessel($y,$g,$v)
{
	include "connect.inc.php";
	$sqltotaldaysy = "SELECT sum(duration) AS ttnd FROM fishoperation ";
	$sqltotaldaysy = $sqltotaldaysy. " WHERE year(SamplingDate)='$y' and VesselId = '$v' and ShipGearId =$g GROUP BY year(SamplingDate)";
	//echo $sqltotalcatchy;
	$qrytotaldaysy = mysql_query($sqltotaldaysy);
	$resgettotaldaysy = mysql_fetch_array($qrytotaldaysy);
	$sumdaysy = $resgettotaldaysy[ttnd];
	return $sumdaysy;
}
function ttdaysyeargear($y,$g)
{
	include "connect.inc.php";
	$sqltotaldaysyg = "SELECT sum(duration)AS ttyg FROM fishoperation inner join gearandmethod on gearandmethod.fgid = fishoperation.ShipGearId";
	$sqltotaldaysyg = $sqltotaldaysyg. " WHERE year( SamplingDate )='$y' and ShipGearId = $g GROUP BY year(SamplingDate)";
	//echo $sqltotalcatchg;
	$qrytotaldaysyg = mysql_query($sqltotaldaysyg);
	$resgettotaldaysyg = mysql_fetch_array($qrytotaldaysyg);
	$sumdaysyg = $resgettotaldaysyg[ttyg];
	return $sumdaysyg;
}
function cpuebymonth($y,$m,$g,$v)
{
	include "connect.inc.php";
	$sqlcpue = "SELECT sum(catchprimary)/sum(duration) AS cpue FROM fishoperation inner join gearandmethod on gearandmethod.fgid = fishoperation.ShipGearId";
	$sqlcpue = $sqlcpue. " WHERE year( SamplingDate )='$y' AND month( SamplingDate )='$m' AND ShipGearId =$g and VesselId = '$v' GROUP BY month(SamplingDate)";
	//echo $sqltotalcatch;
	$qrycpue = mysql_query($sqlcpue);
	$resgetcpue = mysql_fetch_array($qrycpue);
	$sumcpue = $resgetcpue[cpue];
	return $sumcpue;
}

?>