<?
function minlength($l)
{
include "connect.inc.php";
$sqlgetmin = "select min($l) as minlength from biology inner join fishspecies on biology.spid = fishspecies.spid  inner join fishoperation on biology.Optid = fishoperation.Optid INNER JOIN ship ON fishoperation.VesselId = ship.ShipName INNER JOIN shiptype ON ship.fishsector = shiptype.shptid INNER JOIN fishingsector ON shiptype.sid = fishingsector.sid";
//echo $sqlgetmin;
$qrygetmin = mysql_query($sqlgetmin);
$numgetmin = mysql_num_rows($qrygetmin);
if($numgetmin != 0)
{
	$resgetmin = mysql_fetch_array($qrygetmin);
	$minl =  $resgetmin["minlength"];
}
return $minl;
}
function maxlength($l)
{
include "connect.inc.php";
$sqlgetmax = "select max($l) as minlength from biology inner join fishspecies on biology.spid = fishspecies.spid  inner join fishoperation on biology.Optid = fishoperation.Optid INNER JOIN ship ON fishoperation.VesselId = ship.ShipName INNER JOIN shiptype ON ship.fishsector = shiptype.shptid INNER JOIN fishingsector ON shiptype.sid = fishingsector.sid";
//echo $sqlgetmax;
$qrygetmax = mysql_query($sqlgetmax);
$numgetmax = mysql_num_rows($qrygetmax);
if($numgetmax != 0)
{
	$resgetmax = mysql_fetch_array($qrygetmax);
	$maxl =  $resgetmax["minlength"];
}
return $maxl;
}
function getspname($spid)
{
	include "connect.inc.php";
	$sqlgetspname = "select scientific from fishspecies where spid='$spid'";
	$qrygetspname = mysql_query($sqlgetspname);
	$resgetspname = mysql_fetch_array($qrygetspname);
	$spname =  $resgetspname["scientific"];
	return $spname;
}
function getlength($l,$y,$m,$spid,$minl,$maxl)
{
	include "connect.inc.php";
	$sqlgetlength = "select count($l) as countlength from biology inner join fishspecies on biology.spid = fishspecies.spid  inner join fishoperation on biology.Optid = fishoperation.Optid INNER JOIN ship ON fishoperation.VesselId = ship.ShipName INNER JOIN shiptype ON ship.fishsector = shiptype.shptid INNER JOIN fishingsector ON shiptype.sid = fishingsector.sid";
	$sqlgetlength = $sqlgetlength." where year(DepartureDate) = '$y' and month(DepartureDate)='$m' and biology.spid='$spid' and $l between $minl and $maxl";
	//echo $sqlgetlength."<br>"; 
	$qrygetlength = mysql_query($sqlgetlength);
	$resgetlength = mysql_fetch_array($qrygetlength);
	$countl =  $resgetlength["countlength"];
	return $countl;
}
function getsumlength($l,$y,$m,$spid)
{
	include "connect.inc.php";
	$sqlgetlength = "select count($l) as countlength from biology inner join fishspecies on biology.spid = fishspecies.spid  inner join fishoperation on biology.Optid = fishoperation.Optid INNER JOIN ship ON fishoperation.VesselId = ship.ShipName INNER JOIN shiptype ON ship.fishsector = shiptype.shptid INNER JOIN fishingsector ON shiptype.sid = fishingsector.sid";
	$sqlgetlength = $sqlgetlength." where year(DepartureDate) = '$y' and month(DepartureDate)='$m'  and biology.spid='$spid'";
	//echo $sqlgetlength."<br>"; 
	$qrygetlength = mysql_query($sqlgetlength);
	$resgetlength = mysql_fetch_array($qrygetlength);
	$countl2 =  $resgetlength["countlength"];
	return $countl2;
}
?>
