<?php
session_start();

//設定語言
if (isset($_SESSION['lang'])){
	if ($_SESSION['lang'] == "chi"){
		require "language/chi.php";
	} else {
		require "language/eng.php";
	}
	$lang = $_SESSION['lang'];
} else {
	$lang="chi";
	require "language/chi.php";
}
//完成設定語言
require "common.php";
require_once 'phpWord/autoload.php';
// \PhpOffice\PhpWord\Common\Autoloader::register();

//獲取所有POST
foreach ($_POST as $key => $value) 	{ 
	$$key = $value;    //2個$$代表轉為VARIABLE
}
foreach ($_GET as $key => $value) 	{ 
	$$key = $value;    //2個$$代表轉為VARIABLE
}
//完成獲取所有POST
if(isset($_SESSION['STAFFCODE'])){
	$staffcode = $_SESSION['STAFFCODE'];
}

//設定學年
if (!isset($targetschoolyear)){
	$targetschoolyear = $todayschyr;
}
//完成設定學年
//設定計分方式

/*swimming gala
	$absscore = 1;  // 個人項目缺席扣分
	$attscore = 1;	// 個人項目出席並達標加分
	$singlerank = array("9","7","6","5","4","3","2","1"); //25米個人項目排名得分
	$singlerank = array("18","14","12","10","8","6","4","2");//50米或以上個人項目排名得分
	$houserank = array("36","28","30","20","16","12","8","2"); //社制項目排名得分
	$newrecscore = 2; //個人項目新記錄加分
*/

	$absscore = 1;  // 個人項目缺席扣分
	$attscore = 1;	// 個人項目出席並達標加分
	$singlerank = array("9","7","6","5","4","3","2","1"); //個人項目排名得分
	$houserank = array("18","14","12","10","8","6","4","2");//社制項目排名得分
	$newrecscore = 2; //個人項目新記錄加分
	$gradearray = array("A","B","C");
	$sexarray = array("M","F");
	$housearray = array("R","Y","B","G");
//完成設定計分方式

//get title
$sql = mysqli_query($splink,"Select EVENT_CHNAME, EVENT_ENNAME from SCHYEAR where activeyear = \"1\"");
while ($row = mysqli_fetch_row($sql)){
	if ($lang == "chi") {
		$sportdayname = mb_substr($row[0],11);
	} else {
		$sportdayname = mb_substr($row[1],35);
	}
}
$sql = mysqli_query($splink,"Select Start_date , End_date from moduleenable where module=\"sportday\"");
while ($row = mysqli_fetch_row($sql)){
	$startday = $row[0];
	$endday = $row[1];
	$x = 0;
	$chistartday = "";
	while ($x < 10 ) {
		$y = $x+ 1;
		if (substr($startday,$x,1) == 1 ) {
			if ($x == 5 || $x == 8) {
				if (substr($startday,$y, 1)== 0) {
				} else {
					$chistartday .="十";
				}
			} else {
				$chistartday .="一";
			}
		} else if (substr($startday,$x,1) == 2 ) {
			if (($x == 5 || $x == 8 ) && substr($startday,$y, 1) !== 0) {
				$chistartday .= "二十";
			} else {
				$chistartday .="二";
			}
		} else if (substr($startday,$x,1) == 3 ) {
			if (($x == 5 || $x == 8 ) && substr($startday,$y, 1) !== 0) {
				$chistartday .= "三十";
			} else {
				$chistartday .="三";
			}
		} else if (substr($startday,$x,1) == 4 ) {
			$chistartday .="四";
		} else if (substr($startday,$x,1) == 5 ) {
			$chistartday .="五";
		} else if (substr($startday,$x,1) == 6 ) {
			$chistartday .="六";
		} else if (substr($startday,$x,1) == 7 ) {
			$chistartday .="七";
		} else if (substr($startday,$x,1) == 8 ) {
			$chistartday .="八";
		} else if (substr($startday,$x,1) == 9 ) {
			$chistartday .="九";
		} else if (substr($startday,$x,1) == "0" ) {
			if ($x < 5) {
				$chistartday .="零";
			} else if ($x ==6 || $x == 9 ){
				$chistartday .="十";
			} else {
			}
		} else { 
			if ($x == 4) {
				$chistartday .= "年";
			} else {
				$chistartday .= "月";
			}
		}
		$x++;
	}
	$chistartday .="日";
	$chiendday = "";
	$x = 0;
	while ($x < 10 ) {
		$y = $x+ 1;
		if (substr($endday,$x,1) == 1 ) {
			if ($x == 5 || $x == 8) {
				if (substr($endday,$y,1)== 0) {
				} else {
					$chiendday .="十";
				}
			} else {
				$chiendday .="一";
			}
		} else if (substr($endday,$x,1) == 2 ) {
			if (($x == 5 || $x == 8 ) && substr($endday,$y, 1) !== 0) {
				$chiendday .= "二十";
			} else {
				$chiendday .="二";
			}
		} else if (substr($endday,$x,1) == 3 ) {
			if (($x == 5 || $x == 8 ) && substr($endday,$y, 1) !== 0) {
				$chiendday .= "三十";
			} else {
				$chiendday .="三";
			}
		} else if (substr($endday,$x,1) == 4 ) {
			$chiendday .="四";
		} else if (substr($endday,$x,1) == 5 ) {
			$chiendday .="五";
		} else if (substr($endday,$x,1) == 6 ) {
			$chiendday .="六";
		} else if (substr($endday,$x,1) == 7 ) {
			$chiendday .="七";
		} else if (substr($endday,$x,1) == 8 ) {
			$chiendday .="八";
		} else if (substr($endday,$x,1) == 9 ) {
			$chiendday .="九";
		} else if (substr($endday,$x,1) == "0" ) {
			if ($x < 5) {
				$chiendday .="零";
			} else if ($x ==6 || $x == 9 ){
				$chiendday .="十";
			} else {
			}
		} else { 
			if ($x == 4) {
				$chiendday .= "年";
			} else {
				$chiendday .= "月";
			}
		}
		$x++;
	}
	$chiendday .="日";
	$startdayweekn = date("N", strtotime($startday));
	if ($startdayweekn == 1) {
		$startdayweek = "一";
	} else if ($startdayweekn == 2) {
		$startdayweek = "二";
	} else if ($startdayweekn == 3) {
		$startdayweek = "三";
	} else if ($startdayweekn == 4) {
		$startdayweek = "四";
	} else if ($startdayweekn == 5) {
		$startdayweek = "五";
	} else if ($startdayweekn == 6) {
		$startdayweek = "六";
	} else {
		$startdayweek = "日";
	}
	$enddayweekn = date("N", strtotime($endday));
	if ($enddayweekn == 1) {
		$enddayweek = "一";
	} else if ($enddayweekn == 2) {
		$enddayweek = "二";
	} else if ($enddayweekn == 3) {
		$enddayweek = "三";
	} else if ($enddayweekn == 4) {
		$enddayweek = "四";
	} else if ($enddayweekn == 5) {
		$enddayweek = "五";
	} else if ($enddayweekn == 6) {
		$enddayweek = "六";
	} else {
		$enddayweek = "日";
	}

}
//default style
//set text alignment for all cell


//COMPETITION_ID: 45-50 high jump....use special list

//download eventbook
if (isset($downloadeventbook)){
// Creating the new document...
	$phpWord = new \PhpOffice\PhpWord\PhpWord();

/* Note: any element you append to a document must reside inside of a Section. */

//設定標題風格
	$sectionstyle = array('marginTop' => 500, 'marginBottom' =>500, 'marginLeft'=> 1000, 'marginRight' =>1000);
	$bold48 = array( 'name' => '標楷體', 'bold' =>true, 'size'=>48);
	$bold26 = array( 'name' => '標楷體', 'bold' =>true, 'size'=>26);
	$bold18 = array( 'name' => '標楷體', 'bold' =>true, 'size'=>18);
	$bold14singleline = array( 'name' => '標楷體',  'bold' =>true, 'size'=>14, 'underline' => 'single');
	$paracenter = array('align' =>'center');
	$pararight = array('align' =>'right');
	$contentTableStyle = array( 'valign' => 'center','align' => 'center');
	$celltopborder2 = array( 'borderColor' => '000000', 'borderTopSize' => 20,'borderRightSize' => 20,'borderLeftSize' => 20);
	$cellmidborder2 = array( 'borderColor' => '000000', 'borderLeftSize' => 20,'borderRightSize' => 20);
	$cellbottomborder2 = array( 'borderColor' => '000000','borderBottomSize' => 20,'borderRightSize' => 20,'borderLeftSize' => 20);
	$leftcontentTab = array('tabs' => array(new \PhpOffice\PhpWord\Style\Tab('left', 1000),new \PhpOffice\PhpWord\Style\Tab('left', 2500),), 'lineHeight' => '1.5','spaceBefore'=>300);
	$font18 = array( 'name' => '標楷體', 'size'=>18);
	$rundown1font =  array('italic' => true, 'size'=>11);
	$font12 = array( 'name' => '標楷體', 'size'=>12);
	$font12u = array('name' => '標楷體', 'size'=>12, 'underline'=>'single');
	$font10 = array( 'name' => '標楷體', 'size'=>10);
	$font14 = array( 'name' => '標楷體', 'size'=>14);
	$font14u = array('name' => '標楷體', 'size'=>14, 'underline'=>'single');
	$font16 = array( 'name' => '標楷體', 'size'=>16);
	$font16u = array( 'name' => '標楷體', 'size'=>16,'underline'=>'single');
	$contentrowheight = 600;
	$borderall20 = array(  'valign' => 'center', 'borderColor' => '000000', 'borderTopSize' => 20,'borderBottomSize' => 20,'borderLeftSize' => 20,'borderRightSize' => 20);
	$borderall15 = array(  'valign' => 'center', 'borderColor' => '000000', 'borderTopSize' => 15,'borderBottomSize' => 15,'borderLeftSize' => 15,'borderRightSize' => 15);
	$borderall10 = array(  'valign' => 'center', 'borderColor' => '000000', 'borderTopSize' => 10,'borderBottomSize' => 10,'borderLeftSize' => 10,'borderRightSize' => 10);
	$borderbot10lef20 = array( 'borderColor' => '000000','borderLeftSize' => 20,'borderBottomSize' => 10);
	$borderbot10lef20rig20 = array( 'borderColor' => '000000','borderLeftSize' => 20,'borderRightSize' => 20,'borderBottomSize' => 10);
	$borderbot20lef20rig20 = array( 'borderColor' => '000000','borderLeftSize' => 20,'borderRightSize' => 20,'borderBottomSize' => 20);
	$stafflistTab = array('tabs' => array(new \PhpOffice\PhpWord\Style\Tab('left', 2000),));
	$stafflisthead = array('spaceBefore'=>500);
	$parastatistsheader = array('spaceBefore'=>200,'align' =>'center');
	$statistfont =  array( 'name' => '標楷體', 'size'=>12);
	$statistfontb =  array( 'name' => '標楷體', 'size'=>12, 'bold'=>true);
	$bordertop20bot20lef20 = array( 'borderColor' => '000000','borderLeftSize' => 20,'borderTopSize' => 20,'borderBottomSize' => 20);
	$bordertop20bot20lef10 = array( 'borderColor' => '000000','borderLeftSize' => 10,'borderTopSize' => 20,'borderBottomSize' => 20);
	$borderbot10lef10rig20 = array( 'borderColor' => '000000','borderLeftSize' => 10,'borderRightSize' => 20,'borderBottomSize' => 10);
	$bordertop20bot20lef10rig20 =  array(  'valign' => 'center', 'borderColor' => '000000', 'borderTopSize' => 20,'borderBottomSize' => 20,'borderLeftSize' => 10,'borderRightSize' => 20);
	$applisthfstyleu =  array('gridSpan' => 2,'vMerge' => 'restart', 'valign' => 'center', 'borderColor' => '000000','borderTopSize' => 20,'borderBottomSize' => 20,'borderLeftSize' => 20,'borderRightSize' => 20);
	$applisthfstyleb =  array('gridSpan' => 2,'vMerge' => 'continue', 'valign' => 'center', 'borderColor' => '000000','borderBottomSize' => 20,'borderBottomSize' => 20,'borderLeftSize' => 20,'borderRightSize' => 20);
	$tracktabletitle =  array(  'valign' => 'bottom', 'borderColor' => '000000','borderBottomSize' => 20);
	$thankslinespace = array('spaceBefore'=>750);

// Adding an empty Section to the document...
$section = $phpWord->addSection($sectionstyle);
// Adding Text element to the Section having font styled by default...
$section->addText('封面');
$section->addPageBreak();
//目錄
$section->addText('目　　　錄',$bold26,$paracenter);
$section->addImage('img/booksline.jpg');
$section->addTextBreak( null , null , array( 'lineHeight' => '2.0'));
$tablecontent = $section->addTable( $contentTableStyle);
	$tablecontent->addRow($contentrowheight);
	$tablecontent->addCell(8000,$celltopborder2) -> addText("\t一、\t校歌" , $font18 , $leftcontentTab);
	$tablecontent->addRow($contentrowheight);
	$tablecontent->addCell(8000,$cellmidborder2) -> addText("\t二、\t典禮秩序表" , $font18 , $leftcontentTab);
	$tablecontent->addRow($contentrowheight);
	$tablecontent->addCell(8000,$cellmidborder2) -> addText("\t三、\t賽程表" , $font18 , $leftcontentTab);
	$tablecontent->addRow($contentrowheight);
	$tablecontent->addCell(8000,$cellmidborder2) -> addText("\t四、\t陸運會章程及標準成績" , $font18 , $leftcontentTab);
	$tablecontent->addRow($contentrowheight);
	$tablecontent->addCell(8000,$cellmidborder2) -> addText("\t五、\t運動員須知" , $font18 , $leftcontentTab);
	$tablecontent->addRow($contentrowheight);
	$tablecontent->addCell(8000,$cellmidborder2) -> addText("\t六、\t各項比賽紀錄" , $font18 , $leftcontentTab);
	$tablecontent->addRow($contentrowheight);
	$tablecontent->addCell(8000,$cellmidborder2) -> addText("\t七、\t陸運會學生工作人員名單" , $font18 , $leftcontentTab);
	$tablecontent->addRow($contentrowheight);
	$tablecontent->addCell(8000,$cellmidborder2) -> addText("\t八、\t陸運會職員名單" , $font18 , $leftcontentTab);
	$tablecontent->addRow($contentrowheight);
	$tablecontent->addCell(8000,$cellmidborder2) -> addText("\t九、\t參賽人數統計" , $font18 , $leftcontentTab);
	$tablecontent->addRow($contentrowheight);
	$tablecontent->addCell(8000,$cellmidborder2) -> addText("\t十、\t各項賽事參賽者名單" , $font18 , $leftcontentTab);
	$tablecontent->addRow($contentrowheight);
	$tablecontent->addCell(8000,$cellmidborder2) -> addText("\t十一、\t鳴謝" , $font18 , $leftcontentTab);
	$tablecontent->addRow($contentrowheight);
	$tablecontent->addCell(8000,$cellbottomborder2) -> addText("\t十二、\t大球場平面圖" , $font18 , $leftcontentTab);
	
$section->addPageBreak();
//典禮程序
$section->addImage('img/schoolsong.jpg',array('alignment'=>'center','height'=>1020));
$section->addPageBreak();
$section->addText('典 禮 秩 序 表',$bold26,$paracenter);
$section->addImage('img/rundowntitleline.jpg',array('alignment'=>'center','width'=>300));
$tablerundown = $section->addTable($contentTableStyle);
$tablerundown 	->	addRow($contentrowheight);
$tablerundown 	->	addCell(5000,array('borderColor'=>'000000', 'borderTopSize'=> 20,'borderBottomSize'=> 20,'borderLeftSize'=> 20,'borderRightSize'=> 10,'valign'=>'center','align'=>'center'))
				->	addText('Opening Ceremony', array('size'=>18,'underline'=>'wavyHeavy','italic'=> true ), $paracenter);
$tablerundown 	->	addCell(5000,array('borderColor'=>'000000', 'borderTopSize'=> 20,'borderBottomSize'=> 20,'borderLeftSize'=> 10,'borderRightSize'=> 20,'valign'=>'center','align'=>'center'))
				->	addText('開幕典禮', array('size'=>18,'underline'=>'wavyHeavy'), $paracenter);
$tablerundown	->	addRow($contentrowheight);
$tablerundown	->	addCell(5000,array('borderColor'=>'000000', 'borderTopSize'=> 20,'borderLeftSize'=> 20,'borderRightSize'=> 10))
				->	addText('1. Athletes\' Parade', $rundown1font);
$tablerundown 	->	addCell(5000,array('borderColor'=>'000000', 'borderTopSize'=> 20,'borderLeftSize'=> 10,'borderRightSize'=> 20))
				->	addText('一、 運動員代表進場', $font12);
$tablerundown	->	addRow($contentrowheight);
$tablerundown	->	addCell(5000,array('borderColor'=>'000000', 'borderLeftSize'=> 20,'borderRightSize'=> 10))
				->	addText('2. Assembly:School Song', $rundown1font);
$tablerundown 	->	addCell(5000,array('borderColor'=>'000000','borderLeftSize'=> 10,'borderRightSize'=> 20))
				->	addText('二、 集會：唱校歌', $font12);
$tablerundown	->	addRow($contentrowheight + 200);
$c1=$tablerundown->	addCell(5000,array('borderColor'=>'000000', 'borderLeftSize'=> 20,'borderRightSize'=> 10));
	$c1->	addText('3. Opening Speech: Mr. Chan King Tat', $rundown1font);
	$c1->	addText('                                 The Principal', $rundown1font);
$tablerundown 	->	addCell(5000,array('borderColor'=>'000000','borderLeftSize'=> 10,'borderRightSize'=> 20))
				->	addText('三、 致開幕辭：校長XXX先生', $font12);
$tablerundown	->	addRow($contentrowheight);
$tablerundown	->	addCell(5000,array('borderColor'=>'000000','borderLeftSize'=> 20,'borderRightSize'=> 10))
				->	addText('4. Hoisting of School Flag : Scout', $rundown1font);
$tablerundown 	->	addCell(5000,array('borderColor'=>'000000', 'borderLeftSize'=> 10,'borderRightSize'=> 20))
				->	addText('四、 升旗禮：童軍', $font12);
$tablerundown	->	addRow($contentrowheight);
$tablerundown	->	addCell(5000,array('borderColor'=>'000000','borderLeftSize'=> 20,'borderRightSize'=> 10))
				->	addText('5. Vow-taking: House Representatives', $rundown1font);
$tablerundown 	->	addCell(5000,array('borderColor'=>'000000','borderLeftSize'=> 10,'borderRightSize'=> 20))
				->	addText('五、 運動員宣誓：運動員代表', $font12);
$tablerundown	->	addRow($contentrowheight);
$tablerundown	->	addCell(5000,array('borderColor'=>'000000', 'borderBottomSize'=> 20,'borderLeftSize'=> 20,'borderRightSize'=> 10))
				->	addText('6. Competitions Commence', $rundown1font);
$tablerundown 	->	addCell(5000,array('borderColor'=>'000000', 'borderBottomSize'=> 20,'borderLeftSize'=> 10,'borderRightSize'=> 20))
				->	addText('六、 比賽開始', $font12);
				
$section->addTextBreak();

$tablerundown2= $section->addTable($contentTableStyle);
$tablerundown2 	->	addRow($contentrowheight);
$tablerundown2 	->	addCell(5000,array('borderColor'=>'000000', 'borderTopSize'=> 20,'borderBottomSize'=> 20,'borderLeftSize'=> 20,'borderRightSize'=> 10,'valign'=>'center','align'=>'center'))
				->	addText('Prize Presentation Ceremony', array('size'=>18,'underline'=>'wavyHeavy','italic' => true), $paracenter);
$tablerundown2 	->	addCell(5000,array('borderColor'=>'000000', 'borderTopSize'=> 20,'borderBottomSize'=> 20,'borderLeftSize'=> 10,'borderRightSize'=> 20,'valign'=>'center','align'=>'center'))
				->	addText('頒獎典禮', array('size'=>18,'underline'=>'wavyHeavy'), $paracenter);
$tablerundown2	->	addRow($contentrowheight);
$tablerundown2	->	addCell(5000,array('borderColor'=>'000000', 'borderTopSize'=> 20,'borderLeftSize'=> 20,'borderRightSize'=> 10))
				->	addText('1. Assembly / Athletes\' Parade', $rundown1font);
$tablerundown2 	->	addCell(4500,array('borderColor'=>'000000', 'borderTopSize'=> 20,'borderLeftSize'=> 10,'borderRightSize'=> 20))
				->	addText('一、 嘉賓就座∕運動員進場', $font12);
$tablerundown2	->	addRow($contentrowheight);
$tablerundown2	->	addCell(5000,array('borderColor'=>'000000','borderLeftSize'=> 20,'borderRightSize'=> 10))
				->	addText('2. School Song', $rundown1font);
$tablerundown2 	->	addCell(5000,array('borderColor'=>'000000','borderLeftSize'=> 10,'borderRightSize'=> 20))
				->	addText('二、 唱校歌', $font12);
$tablerundown2	->	addRow($contentrowheight + 200);
$c1 = $tablerundown2	->	addCell(4500,array('borderColor'=>'000000', 'borderLeftSize'=> 20,'borderRightSize'=> 10));
	$c1->	addText('3. Welcoming Address : Mr. XXX ', $rundown1font);
	$c1->	addText('                                      The Principal', $rundown1font);	
$tablerundown2 	->	addCell(5000,array('borderColor'=>'000000', 'borderLeftSize'=> 10,'borderRightSize'=> 20))
				->	addText('三、 致歡迎辭：校長XXX先生', $font12);
$tablerundown2	->	addRow($contentrowheight);
$tablerundown2	->	addCell(5000,array('borderColor'=>'000000', 'borderLeftSize'=> 20,'borderRightSize'=> 10))
				->	addText('4. Address : XXXXXXXXXX', $rundown1font);
$tablerundown2 	->	addCell(5000,array('borderColor'=>'000000','borderLeftSize'=> 10,'borderRightSize'=> 20))
				->	addText('四、 致辭： XXXXXXXXXXXX', $font12);
$tablerundown2	->	addRow($contentrowheight);
$tablerundown2	->	addCell(5000,array('borderColor'=>'000000','borderLeftSize'=> 20,'borderRightSize'=> 10))
				->	addText('5. Presentation of Prizes : Honourable Guests', $rundown1font);
$tablerundown2 	->	addCell(5000,array('borderColor'=>'000000','borderLeftSize'=> 10,'borderRightSize'=> 20))
				->	addText('五、 頒獎：各位嘉賓', $font12);
$tablerundown2	->	addRow($contentrowheight);
$c2 = $tablerundown2	->	addCell(5000,array('borderColor'=>'000000', 'borderLeftSize'=> 20,'borderRightSize'=> 10));
	$c2	->	addText('6. Presentation of Souvenir : Mr. XXX', $rundown1font);
	$c2	->	addText('                                             The Principal', $rundown1font);
$tablerundown2 	->	addCell(5000,array('borderColor'=>'000000','borderLeftSize'=> 10,'borderRightSize'=> 20))
				->	addText('六、 致送紀念品：校長XXX先生', $font12);
$tablerundown2	->	addRow($contentrowheight);
$c3 =$tablerundown2	->	addCell(5000,array('borderColor'=>'000000', 'borderLeftSize'=> 20,'borderRightSize'=> 10));
	$c3	->	addText('7. Vote of Thanks : Mr XXXXXXXXX', $rundown1font);
	$c3	->	addText('                              The Chairman, Student Union', $rundown1font);
$tablerundown2 	->	addCell(5000,array('borderColor'=>'000000', 'borderLeftSize'=> 10,'borderRightSize'=> 20))
				->	addText('七、 致謝辭：學生會會長XXX同學', $font12);
$tablerundown2	->	addRow($contentrowheight);
$tablerundown2	->	addCell(5000,array('borderColor'=>'000000', 'borderLeftSize'=> 20,'borderRightSize'=> 10))
				->	addText('8. Lowering of School Flag : Scout', $rundown1font);
$tablerundown2 	->	addCell(5000,array('borderColor'=>'000000','borderLeftSize'=> 10,'borderRightSize'=> 20))
				->	addText('八、 降旗禮：童軍', $font12);
$tablerundown2	->	addRow($contentrowheight);
$tablerundown2	->	addCell(5000,array('borderColor'=>'000000', 'borderBottomSize'=> 20,'borderLeftSize'=> 20,'borderRightSize'=> 10))
				->	addText('9. End of Ceremony', $rundown1font);
$tablerundown2 	->	addCell(5000,array('borderColor'=>'000000', 'borderBottomSize'=> 20,'borderLeftSize'=> 10,'borderRightSize'=> 20))
				->	addText('九、 禮成', $font12);

$section->addPageBreak();

//賽程表
$section-> addText($company,$bold18,$paracenter);
$section-> addText($sportdayname,$bold18,$paracenter);
$section-> addText('賽 程 表', $bold14singleline, $paracenter);

$section->addTextBreak();
$section->addPageBreak();

//比賽章程

$eventruletop = array('tabs' => array(new \PhpOffice\PhpWord\Style\Tab('left', 700),new \PhpOffice\PhpWord\Style\Tab('left', 2500),), 'lineHeight' => '1.5');


$sql = mysqli_query($splink,"Select MAX(CASE WHEN grade = \"A\" THEN gradeyear END),MAX(CASE WHEN grade = \"B\" THEN gradeyear END),MAX(CASE WHEN grade = \"C\" THEN gradeyear END) from gradeyear where SCHYEAR=\"".$todayschyr."\"");
while ($row = mysqli_fetch_row($sql)){
	$chiAyear = "";
	$Aendyear = $row[0] + 1;
	$i=0;
	while ($i < 4 ) {
		if (substr($Aendyear,$i,1) == 1) {
			$chiAyear .= "一";
		} else if (substr($Aendyear,$i,1) == 2) {
			$chiAyear .= "二";
		} else if (substr($Aendyear,$i,1) == 3) {
			$chiAyear .= "三";
		} else if (substr($Aendyear,$i,1) == 4) {
			$chiAyear .= "四";
		} else if (substr($Aendyear,$i,1) == 5) {
			$chiAyear .= "五";
		} else if (substr($Aendyear,$i,1) == 6) {
			$chiAyear .= "六";
		} else if (substr($Aendyear,$i,1) == 7) {
			$chiAyear .= "七";
		} else if (substr($Aendyear,$i,1) == 8) {
			$chiAyear .= "八";
		} else if (substr($Aendyear,$i,1) == 9) {
			$chiAyear .= "九";
		} else {
			$chiAyear .= "零";			
		}
		$i++;
	}
	$chiByear = "";
	$i=0;
	while ($i < 4 ) {
		if (substr($row[1],$i,1) == 1) {
			$chiByear .= "一";
		} else if (substr($row[1],$i,1) == 2) {
			$chiByear .= "二";
		} else if (substr($row[1],$i,1) == 3) {
			$chiByear .= "三";
		} else if (substr($row[1],$i,1) == 4) {
			$chiByear .= "四";
		} else if (substr($row[1],$i,1) == 5) {
			$chiByear .= "五";
		} else if (substr($row[1],$i,1) == 6) {
			$chiByear .= "六";
		} else if (substr($row[1],$i,1) == 7) {
			$chiByear .= "七";
		} else if (substr($row[1],$i,1) == 8) {
			$chiByear .= "八";
		} else if (substr($row[1],$i,1) == 9) {
			$chiByear .= "九";
		} else {
			$chiByear .= "零";			
		}
		$i++;
	}
	$Bendyear = $row[1] + 1;
	$chiBendyear = "";
	$i=0;
	while ($i < 4 ) {
		if (substr($Bendyear,$i,1) == 1) {
			$chiBendyear .= "一";
		} else if (substr($Bendyear,$i,1) == 2) {
			$chiBendyear .= "二";
		} else if (substr($Bendyear,$i,1) == 3) {
			$chiBendyear .= "三";
		} else if (substr($Bendyear,$i,1) == 4) {
			$chiBendyear .= "四";
		} else if (substr($Bendyear,$i,1) == 5) {
			$chiBendyear .= "五";
		} else if (substr($Bendyear,$i,1) == 6) {
			$chiBendyear .= "六";
		} else if (substr($Bendyear,$i,1) == 7) {
			$chiBendyear .= "七";
		} else if (substr($Bendyear,$i,1) == 8) {
			$chiBendyear .= "八";
		} else if (substr($Bendyear,$i,1) == 9) {
			$chiBendyear .= "九";
		} else {
			$chiBendyear .= "零";			
		}
		$i++;
	}
	$chiCyear = "";
	$i=0;
	while ($i < 4 ) {
		if (substr($row[2],$i,1) == 1) {
			$chiCyear .= "一";
		} else if (substr($row[2],$i,1) == 2) {
			$chiCyear .= "二";
		} else if (substr($row[2],$i,1) == 3) {
			$chiCyear .= "三";
		} else if (substr($row[2],$i,1) == 4) {
			$chiCyear .= "四";
		} else if (substr($row[2],$i,1) == 5) {
			$chiCyear .= "五";
		} else if (substr($row[2],$i,1) == 6) {
			$chiCyear .= "六";
		} else if (substr($row[2],$i,1) == 7) {
			$chiCyear .= "七";
		} else if (substr($row[2],$i,1) == 8) {
			$chiCyear .= "八";
		} else if (substr($row[2],$i,1) == 9) {
			$chiCyear .= "九";
		} else {
			$chiCyear .= "零";			
		}
		$i++;
	}

}

$section-> addText($company,$bold18,$paracenter);
$section-> addText($sportdayname,$bold18,$paracenter);
$section-> addText('比 賽 章 程', $bold14singleline, $paracenter);
$section-> addTextBreak();
$section-> addText("(一)\t日　　期：\t".$chistartday."(星期".$startdayweek.")及".$chiendday."(星期".$enddayweek.")", $font12 ,$eventruletop);
$section-> addText("(二)\t地　　點：\t元朗大球場", $font12,$eventruletop);
$section-> addText("(三)\t參賽單位：\t以本校各社為比賽單位", $font12,$eventruletop);
$section-> addText("(四)\t分　　組：\t分男、女子各甲、乙、丙六組", $font12,$eventruletop);
$section-> addText("\t\t甲組：".$chiAyear."年十二月三十一日或以前出生者。", $font12,$eventruletop);
$section-> addText("\t\t乙組：".$chiByear."年一月一日至".$chiBendyear."年十二月三十一日出生者。", $font12,$eventruletop);
$section-> addText("\t\t丙組：".$chiCyear."年或以後出生者。", $font12,$eventruletop);

$section->addText("田項標準：",$font12);
$tablefieldstandard = $section -> addTable($contentTableStyle);
$tablefieldstandard ->	addRow(400);
$cell1 = $tablefieldstandard ->	addCell(1000, array('borderColor'=>'000000','borderLeftSize'=> 20,'borderBottomSize'=> 20,'borderTopSize'=> 20, 'vMerge' => 'restart', 'valign' => 'center'));
$textrun1 = $cell1 -> addTextRun(array('alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER));
$textrun1 -> 	addText('組別', $font14, $paracenter);
$cell2 = $tablefieldstandard ->	addCell(2000, array('borderColor'=>'000000','borderLeftSize'=> 10,'borderBottomSize'=> 20,'borderTopSize'=> 20,'borderRightSize'=> 15,'vMerge' => 'restart', 'valign' => 'center'));
$textrun2 = $cell2 -> addTextRun(array('alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER));
$textrun2 ->	addText('標準', $font14, $paracenter);
$cell3 = $tablefieldstandard ->	addCell(6000, array('borderColor'=>'000000','borderBottomSize'=> 10,'borderRightSize'=> 20,'borderTopSize'=> 20,'gridSpan' => 6, 'valign' => 'center'));
$textrun3 = $cell3 -> addTextRun(array('alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER));
$textrun3 ->	addText('項目成績(m)', $font14, $paracenter);
$tablefieldstandard -> addRow(400);
$tablefieldstandard ->	addCell( null, array('borderColor'=>'000000','borderBottomSize'=> 20,'borderLeftSize'=> 20,'borderRightSize'=> 10,'vMerge' => 'continue'));
$tablefieldstandard ->	addCell( null, array('borderColor'=>'000000','borderBottomSize'=> 20,'borderRightSize'=> 15,'vMerge' => 'continue'));
$c1 = $tablefieldstandard ->	addCell(1000,array('borderColor'=>'000000','borderBottomSize'=> 20,'borderRightSize'=> 15,'valign' => 'center'));
$c1 ->	addText("跳高",$font12,$paracenter);
$c1 ->	addText("(HJ)",$font12,$paracenter);
$c2 = $tablefieldstandard ->	addCell(1000,array('borderColor'=>'000000','borderBottomSize'=> 20,'borderRightSize'=> 15,'valign' => 'center'));
$c2 ->	addText("跳遠",$font12, $paracenter);
$c2 ->	addText("(LJ)",$font12,$paracenter);
$c3 = $tablefieldstandard ->	addCell(1000,array('borderColor'=>'000000','borderBottomSize'=> 20,'borderRightSize'=> 15,'valign' => 'center'));
$c3 ->	addText("三級跳",$font12,$paracenter);
$c3 ->	addText("(TJ)",$font12,$paracenter);
$c4 = $tablefieldstandard ->	addCell(1000,array('borderColor'=>'000000','borderBottomSize'=> 20,'borderRightSize'=> 15,'valign' => 'center'));
$c4 ->	addText("鉛球",$font12,$paracenter);
$c4 ->	addText("(SP)",$font12,$paracenter);
$c5 = $tablefieldstandard ->	addCell(1000,array('borderColor'=>'000000','borderBottomSize'=> 20,'borderRightSize'=> 15,'valign' => 'center'));
$c5 ->	addText("鐵餅",$font12,$paracenter);
$c5 ->	addText("(DIS)",$font12,$paracenter);
$c6 = $tablefieldstandard ->	addCell(1000,array('borderColor'=>'000000','borderBottomSize'=> 20,'borderRightSize'=> 20,'valign' => 'center'));
$c6 ->	addText("標槍",$font12,$paracenter);
$c6 ->	addText("(JAV)",$font12,$paracenter);
$tablefieldstandard ->addRow(400);
$cellfba=$tablefieldstandard->addCell(1000, array('borderColor'=>'000000','borderLeftSize'=> 20,'borderRightSize'=>10,'vMerge' => 'restart', 'valign' => 'center'));
$cellfba ->	addText("男甲",$font18,$paracenter);

$bordertop20bot10lef10rig15 = array('borderColor'=>'000000','borderTopSize'=> 20,'borderleftSize'=> 10,'borderBottomSize'=> 10,'borderRightSize'=> 15,'valign' => 'center');
$bordertop20bot10lef15rig15 = array('borderColor'=>'000000','borderTopSize'=> 20,'borderleftSize'=> 15,'borderBottomSize'=> 10,'borderRightSize'=> 15,'valign' => 'center');
$bordertop20bot10lef15rig20 = array('borderColor'=>'000000','borderTopSize'=> 20,'borderleftSize'=> 15,'borderBottomSize'=> 10,'borderRightSize'=> 20,'valign' => 'center');
$borderbot15lef10rig15 = array('borderColor'=>'000000','borderleftSize'=> 10,'borderBottomSize'=> 15,'borderRightSize'=> 15,'valign' => 'center');
$borderbot15rig15 = array('borderColor'=>'000000','borderBottomSize'=> 15,'borderRightSize'=> 15,'valign' => 'center');
$borderbot15rig20 = array('borderColor'=>'000000','borderBottomSize'=> 15,'borderRightSize'=> 20,'valign' => 'center');
$borderbot10lef10rig15=array('borderColor'=>'000000','borderleftSize'=> 10,'borderBottomSize'=> 10,'borderRightSize'=> 15,'valign' => 'center');
$borderbot10lef15rig15=array('borderColor'=>'000000','borderleftSize'=> 15,'borderBottomSize'=> 10,'borderRightSize'=> 15,'valign' => 'center');
$borderbot10lef15rig20=array('borderColor'=>'000000','borderleftSize'=> 15,'borderBottomSize'=> 10,'borderRightSize'=> 20,'valign' => 'center');

$showhjs="";
$showhjm = "";
$sql = mysqli_query($splink,"Select STANDARD, MEASURE from COMPETITIONITEM where keyid=\"45\"");
while ($row = mysqli_fetch_row($sql)){
	$showhjs = $row[0];
	$showhjm = $row[1];
}
$showljs="";
$showljm = "";
$sql = mysqli_query($splink,"Select STANDARD, MEASURE from COMPETITIONITEM where keyid=\"67\"");
while ($row = mysqli_fetch_row($sql)){
	$showljs = $row[0];
	$showljm = $row[1];
}
$showtjs="";
$showtjm = "";
$sql = mysqli_query($splink,"Select STANDARD, MEASURE from COMPETITIONITEM where keyid=\"79\"");
while ($row = mysqli_fetch_row($sql)){
	$showtjs = $row[0];
	$showtjm = $row[1];
}
$showsps="";
$showspm = "";
$sql = mysqli_query($splink,"Select STANDARD, MEASURE from COMPETITIONITEM where keyid=\"73\"");
while ($row = mysqli_fetch_row($sql)){
	$showsps = $row[0];
	$showspm = $row[1];
}
$showdiss="";
$showdism = "";
$sql = mysqli_query($splink,"Select STANDARD, MEASURE from COMPETITIONITEM where keyid=\"41\"");
while ($row = mysqli_fetch_row($sql)){
	$showdiss = $row[0];
	$showdism = $row[1];
}
$showjavs="";
$showjavm = "";
$sql = mysqli_query($splink,"Select STANDARD, MEASURE from COMPETITIONITEM where keyid=\"63\"");
while ($row = mysqli_fetch_row($sql)){
	$showjavs = $row[0];
	$showjavm = $row[1];
}
$tablefieldstandard -> addCell(2000,$bordertop20bot10lef10rig15) -> addText("獲標準分成績",$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$bordertop20bot10lef15rig15) -> addText($showhjs,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$bordertop20bot10lef15rig15) -> addText($showljs,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$bordertop20bot10lef15rig15) -> addText($showtjs,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$bordertop20bot10lef15rig15) -> addText($showsps,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$bordertop20bot10lef15rig15) -> addText($showdiss,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$bordertop20bot10lef15rig20) -> addText($showjavs,$font14,$paracenter);
$tablefieldstandard ->addRow(400);
$tablefieldstandard ->	addCell( null, array('borderColor'=>'000000','borderBottomSize'=> 15,'borderLeftSize'=> 20,'borderRightSize'=> 10,'vMerge' => 'continue'));
$tablefieldstandard -> addCell(1000,$borderbot15lef10rig15) -> addText("量度標準",$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot15rig15) -> addText($showhjm,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot15rig15) -> addText($showljm,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot15rig15) -> addText($showtjm,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot15rig15) -> addText($showsps,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot15rig15) -> addText($showdism,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot15rig20) -> addText($showjavm,$font14,$paracenter);


$tablefieldstandard ->addRow(400);
$cellfba=$tablefieldstandard->addCell(1000, array('borderColor'=>'000000','borderLeftSize'=> 20,'borderRightSize'=>10,'vMerge' => 'restart', 'valign' => 'center'));
$cellfba ->	addText("男乙",$font18,$paracenter);
$showhjs="";
$showhjm = "";
$sql = mysqli_query($splink,"Select STANDARD, MEASURE from COMPETITIONITEM where keyid=\"47\"");
while ($row = mysqli_fetch_row($sql)){
	$showhjs = $row[0];
	$showhjm = $row[1];
}
$showljs="";
$showljm = "";
$sql = mysqli_query($splink,"Select STANDARD, MEASURE from COMPETITIONITEM where keyid=\"69\"");
while ($row = mysqli_fetch_row($sql)){
	$showljs = $row[0];
	$showljm = $row[1];
}
$showtjs="";
$showtjm = "";
$sql = mysqli_query($splink,"Select STANDARD, MEASURE from COMPETITIONITEM where keyid=\"80\"");
while ($row = mysqli_fetch_row($sql)){
	$showtjs = $row[0];
	$showtjm = $row[1];
}
$showsps="";
$showspm = "";
$sql = mysqli_query($splink,"Select STANDARD, MEASURE from COMPETITIONITEM where keyid=\"75\"");
while ($row = mysqli_fetch_row($sql)){
	$showsps = $row[0];
	$showspm = $row[1];
}
$showdiss="";
$showdism = "";
$sql = mysqli_query($splink,"Select STANDARD, MEASURE from COMPETITIONITEM where keyid=\"43\"");
while ($row = mysqli_fetch_row($sql)){
	$showdiss = $row[0];
	$showdism = $row[1];
}
$showjavs="";
$showjavm = "";
$sql = mysqli_query($splink,"Select STANDARD, MEASURE from COMPETITIONITEM where keyid=\"65\"");
while ($row = mysqli_fetch_row($sql)){
	$showjavs = $row[0];
	$showjavm = $row[1];
}
$tablefieldstandard -> addCell(2000,$borderbot10lef10rig15) -> addText("獲標準分成績",$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot10lef15rig15) -> addText($showhjs,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot10lef15rig15) -> addText($showljs,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot10lef15rig15) -> addText($showtjs,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot10lef15rig15) -> addText($showsps,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot10lef15rig15) -> addText($showdiss,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot10lef15rig20) -> addText($showjavs,$font14,$paracenter);
$tablefieldstandard ->addRow(400);
$tablefieldstandard ->	addCell( null, array('borderColor'=>'000000','borderBottomSize'=> 15,'borderLeftSize'=> 20,'borderRightSize'=> 10,'vMerge' => 'continue'));
$tablefieldstandard -> addCell(1000,$borderbot15lef10rig15) -> addText("量度標準",$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot15rig15) -> addText($showhjm,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot15rig15) -> addText($showljm,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot15rig15) -> addText($showtjm,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot15rig15) -> addText($showspm,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot15rig15) -> addText($showdism,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot15rig20) -> addText($showjavm,$font14,$paracenter);

$tablefieldstandard ->addRow(400);
$cellfba=$tablefieldstandard->addCell(1000, array('borderColor'=>'000000','borderLeftSize'=> 20,'borderRightSize'=>10,'vMerge' => 'restart', 'valign' => 'center'));
$cellfba ->	addText("男丙",$font18,$paracenter);
$showhjs="";
$showhjm = "";
$sql = mysqli_query($splink,"Select STANDARD, MEASURE from COMPETITIONITEM where keyid=\"49\"");
while ($row = mysqli_fetch_row($sql)){
	$showhjs = $row[0];
	$showhjm = $row[1];
}
$showljs="";
$showljm = "";
$sql = mysqli_query($splink,"Select STANDARD, MEASURE from COMPETITIONITEM where keyid=\"71\"");
while ($row = mysqli_fetch_row($sql)){
	$showljs = $row[0];
	$showljm = $row[1];
}
$showtjs="";
$showtjm = "";
$showsps="";
$showspm = "";
$sql = mysqli_query($splink,"Select STANDARD, MEASURE from COMPETITIONITEM where keyid=\"77\"");
while ($row = mysqli_fetch_row($sql)){
	$showsps = $row[0];
	$showspm = $row[1];
}
$showdiss="";
$showdism = "";
$showjavs="";
$showjavm = "";
$tablefieldstandard -> addCell(2000,$borderbot10lef10rig15) -> addText("獲標準分成績",$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot10lef15rig15) -> addText($showhjs,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot10lef15rig15) -> addText($showljs,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot10lef15rig15) -> addText($showtjs,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot10lef15rig15) -> addText($showsps,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot10lef15rig15) -> addText($showdiss,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot10lef15rig20) -> addText($showjavs,$font14,$paracenter);
$tablefieldstandard ->addRow(400);
$tablefieldstandard ->	addCell( null, array('borderColor'=>'000000','borderBottomSize'=> 15,'borderLeftSize'=> 20,'borderRightSize'=> 10,'vMerge' => 'continue'));
$tablefieldstandard -> addCell(1000,$borderbot15lef10rig15) -> addText("量度標準",$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot15rig15) -> addText($showhjm,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot15rig15) -> addText($showljm,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot15rig15) -> addText($showtjm,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot15rig15) -> addText($showspm,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot15rig15) -> addText($showdism,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot15rig20) -> addText($showjavm,$font14,$paracenter);

$tablefieldstandard ->addRow(400);
$cellfba=$tablefieldstandard->addCell(1000, array('borderColor'=>'000000','borderLeftSize'=> 20,'borderRightSize'=>10,'vMerge' => 'restart', 'valign' => 'center'));
$cellfba ->	addText("女甲",$font18,$paracenter);
$showhjs="";
$showhjm = "";
$sql = mysqli_query($splink,"Select STANDARD, MEASURE from COMPETITIONITEM where keyid=\"46\"");
while ($row = mysqli_fetch_row($sql)){
	$showhjs = $row[0];
	$showhjm = $row[1];
}
$showljs="";
$showljm = "";
$sql = mysqli_query($splink,"Select STANDARD, MEASURE from COMPETITIONITEM where keyid=\"68\"");
while ($row = mysqli_fetch_row($sql)){
	$showljs = $row[0];
	$showljm = $row[1];
}
$showtjs="";
$showtjm = "";
$showsps="";
$showspm = "";
$sql = mysqli_query($splink,"Select STANDARD, MEASURE from COMPETITIONITEM where keyid=\"74\"");
while ($row = mysqli_fetch_row($sql)){
	$showsps = $row[0];
	$showspm = $row[1];
}
$showdiss="";
$showdism = "";
$sql = mysqli_query($splink,"Select STANDARD, MEASURE from COMPETITIONITEM where keyid=\"42\"");
while ($row = mysqli_fetch_row($sql)){
	$showdiss = $row[0];
	$showdism = $row[1];
}
$showjavs="";
$showjavm = "";
$sql = mysqli_query($splink,"Select STANDARD, MEASURE from COMPETITIONITEM where keyid=\"64\"");
while ($row = mysqli_fetch_row($sql)){
	$showjavs = $row[0];
	$showjavm = $row[1];
}
$tablefieldstandard -> addCell(2000,$borderbot10lef10rig15) -> addText("獲標準分成績",$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot10lef15rig15) -> addText($showhjs,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot10lef15rig15) -> addText($showljs,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot10lef15rig15) -> addText($showtjs,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot10lef15rig15) -> addText($showsps,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot10lef15rig15) -> addText($showdiss,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot10lef15rig20) -> addText($showjavs,$font14,$paracenter);
$tablefieldstandard ->addRow(400);
$tablefieldstandard ->	addCell( null, array('borderColor'=>'000000','borderBottomSize'=> 15,'borderLeftSize'=> 20,'borderRightSize'=> 10,'vMerge' => 'continue'));
$tablefieldstandard -> addCell(1000,$borderbot15lef10rig15) -> addText("量度標準",$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot15rig15) -> addText($showhjm,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot15rig15) -> addText($showljm,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot15rig15) -> addText($showtjm,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot15rig15) -> addText($showspm,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot15rig15) -> addText($showdism,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot15rig20) -> addText($showjavm,$font14,$paracenter);

$tablefieldstandard ->addRow(400);
$cellfba=$tablefieldstandard->addCell(1000, array('borderColor'=>'000000','borderLeftSize'=> 20,'borderRightSize'=>10,'vMerge' => 'restart', 'valign' => 'center'));
$cellfba ->	addText("女乙",$font18,$paracenter);
$showhjs="";
$showhjm = "";
$sql = mysqli_query($splink,"Select STANDARD, MEASURE from COMPETITIONITEM where keyid=\"48\"");
while ($row = mysqli_fetch_row($sql)){
	$showhjs = $row[0];
	$showhjm = $row[1];
}
$showljs="";
$showljm = "";
$sql = mysqli_query($splink,"Select STANDARD, MEASURE from COMPETITIONITEM where keyid=\"70\"");
while ($row = mysqli_fetch_row($sql)){
	$showljs = $row[0];
	$showljm = $row[1];
}
$showtjs="";
$showtjm = "";
$showsps="";
$showspm = "";
$sql = mysqli_query($splink,"Select STANDARD, MEASURE from COMPETITIONITEM where keyid=\"76\"");
while ($row = mysqli_fetch_row($sql)){
	$showsps = $row[0];
	$showspm = $row[1];
}
$showdiss="";
$showdism = "";
$sql = mysqli_query($splink,"Select STANDARD, MEASURE from COMPETITIONITEM where keyid=\"44\"");
while ($row = mysqli_fetch_row($sql)){
	$showdiss = $row[0];
	$showdism = $row[1];
}
$showjavs="";
$showjavm = "";
$sql = mysqli_query($splink,"Select STANDARD, MEASURE from COMPETITIONITEM where keyid=\"66\"");
while ($row = mysqli_fetch_row($sql)){
	$showjavs = $row[0];
	$showjavm = $row[1];
}

$tablefieldstandard -> addCell(2000,$borderbot10lef10rig15) -> addText("獲標準分成績",$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot10lef15rig15) -> addText($showhjs,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot10lef15rig15) -> addText($showljs,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot10lef15rig15) -> addText($showtjs,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot10lef15rig15) -> addText($showsps,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot10lef15rig15) -> addText($showdiss,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot10lef15rig20) -> addText($showjavs,$font14,$paracenter);
$tablefieldstandard ->addRow(400);
$tablefieldstandard ->	addCell( null, array('borderColor'=>'000000','borderBottomSize'=> 15,'borderLeftSize'=> 20,'borderRightSize'=> 10,'vMerge' => 'continue'));
$tablefieldstandard -> addCell(1000,$borderbot15lef10rig15) -> addText("量度標準",$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot15rig15) -> addText($showhjm,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot15rig15) -> addText($showljm,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot15rig15) -> addText($showtjm,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot15rig15) -> addText($showspm,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot15rig15) -> addText($showdism,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot15rig20) -> addText($showjavm,$font14,$paracenter);

$tablefieldstandard ->addRow(400);
$cellfba=$tablefieldstandard->addCell(1000, array('borderColor'=>'000000','borderLeftSize'=> 20,'borderRightSize'=>10,'vMerge' => 'restart', 'valign' => 'center'));
$cellfba ->	addText("女丙",$font18,$paracenter);
$showhjs="";
$showhjm = "";
$sql = mysqli_query($splink,"Select STANDARD, MEASURE from COMPETITIONITEM where keyid=\"50\"");
while ($row = mysqli_fetch_row($sql)){
	$showhjs = $row[0];
	$showhjm = $row[1];
}
$showljs="";
$showljm = "";
$sql = mysqli_query($splink,"Select STANDARD, MEASURE from COMPETITIONITEM where keyid=\"50\"");
while ($row = mysqli_fetch_row($sql)){
	$showljs = $row[0];
	$showljm = $row[1];
}
$showtjs="";
$showtjm = "";
$showsps="";
$showspm = "";
$sql = mysqli_query($splink,"Select STANDARD, MEASURE from COMPETITIONITEM where keyid=\"78\"");
while ($row = mysqli_fetch_row($sql)){
	$showsps = $row[0];
	$showspm = $row[1];
}
$showdiss="";
$showdism = "";
$showjavs="";
$showjavm = "";
$tablefieldstandard -> addCell(2000,$borderbot10lef10rig15) -> addText("獲標準分成績",$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot10lef15rig15) -> addText($showhjs,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot10lef15rig15) -> addText($showljs,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot10lef15rig15) -> addText($showtjs,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot10lef15rig15) -> addText($showsps,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot10lef15rig15) -> addText($showdiss,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot10lef15rig20) -> addText($showjavs,$font14,$paracenter);
$tablefieldstandard ->addRow(400);
$tablefieldstandard ->	addCell( null, array('borderColor'=>'000000','borderBottomSize'=> 15,'borderLeftSize'=> 20,'borderRightSize'=> 10,'vMerge' => 'continue'));
$tablefieldstandard -> addCell(1000,$borderbot15lef10rig15) -> addText("量度標準",$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot15rig15) -> addText($showhjm,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot15rig15) -> addText($showljm,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot15rig15) -> addText($showtjm,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot15rig15) -> addText($showspm,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot15rig15) -> addText($showdism,$font14,$paracenter);
$tablefieldstandard -> addCell(1000,$borderbot15rig20) -> addText($showjavm,$font14,$paracenter);


$section->addTextBreak();
$section->addText("徑項標準：",$font12);
$tabletrackstandard = $section -> addTable($contentTableStyle);
$tabletrackstandard ->	addRow(400);
$tabletrackstandard ->	addCell(1000, array('borderColor'=>'000000','borderLeftSize'=> 20,'borderBottomSize'=> 20,'borderTopSize'=> 20, 'vMerge' => 'restart', 'valign' => 'center'))
	->addText("組別",$font14,$paracenter);
$tabletrackstandard ->	addCell(1000, array('borderColor'=>'000000','borderLeftSize'=> 10,'borderBottomSize'=> 20,'borderTopSize'=> 20, 'vMerge' => 'restart', 'valign' => 'center'))
	->addText("100m",$font14,$paracenter);
$tabletrackstandard ->	addCell(1000, array('borderColor'=>'000000','borderLeftSize'=> 10,'borderBottomSize'=> 20,'borderTopSize'=> 20, 'vMerge' => 'restart', 'valign' => 'center'))
	->addText("100/110mH",$font14,$paracenter);
$tabletrackstandard ->	addCell(1000, array('borderColor'=>'000000','borderLeftSize'=> 10,'borderBottomSize'=> 20,'borderTopSize'=> 20, 'vMerge' => 'restart', 'valign' => 'center'))
	->addText("200m",$font14,$paracenter);
$tabletrackstandard ->	addCell(1000, array('borderColor'=>'000000','borderLeftSize'=> 10,'borderBottomSize'=> 20,'borderTopSize'=> 20, 'vMerge' => 'restart', 'valign' => 'center'))
	->addText("400m",$font14,$paracenter);
$tabletrackstandard ->	addCell(1000, array('borderColor'=>'000000','borderLeftSize'=> 10,'borderBottomSize'=> 20,'borderTopSize'=> 20, 'vMerge' => 'restart', 'valign' => 'center'))
	->addText("800m",$font14,$paracenter);
$tabletrackstandard ->	addCell(1000, array('borderColor'=>'000000','borderLeftSize'=> 10,'borderBottomSize'=> 20,'borderTopSize'=> 20, 'vMerge' => 'restart', 'valign' => 'center'))
	->addText("1500m",$font14,$paracenter);
$tabletrackstandard ->	addCell(1000, array('borderColor'=>'000000','borderLeftSize'=> 10,'borderRightSize'=> 20,'borderBottomSize'=> 20,'borderTopSize'=> 20, 'vMerge' => 'restart', 'valign' => 'center'))
	->addText("3000m",$font14,$paracenter);

$borderbot10lef20=  array('borderColor'=>'000000','borderLeftSize'=> 20,'borderBottomSize'=> 10, 'vMerge' => 'restart', 'valign' => 'center');
$borderbot10lef10=  array('borderColor'=>'000000','borderLeftSize'=> 10,'borderBottomSize'=> 10, 'vMerge' => 'restart', 'valign' => 'center');
$borderbot10lef10rig20  =  array('borderColor'=>'000000','borderRightSize'=> 20,'borderLeftSize'=> 10,'borderBottomSize'=> 10, 'vMerge' => 'restart', 'valign' => 'center');
$borderbot20lef20=  array('borderColor'=>'000000','borderLeftSize'=> 20,'borderBottomSize'=> 20, 'vMerge' => 'restart', 'valign' => 'center');
$borderbot20lef10=  array('borderColor'=>'000000','borderLeftSize'=> 10,'borderBottomSize'=> 20, 'vMerge' => 'restart', 'valign' => 'center');
$borderbot20lef10rig20  =  array('borderColor'=>'000000','borderRightSize'=> 20,'borderLeftSize'=> 10,'borderBottomSize'=> 20, 'vMerge' => 'restart', 'valign' => 'center');

$show10="";
$sql = mysqli_query($splink,"Select STANDARD from COMPETITIONITEM where keyid=\"1\"");
while ($row = mysqli_fetch_row($sql)){
	$temp = explode(":",$row[0]);
	if ($temp[0] == "00") {
		if ($temp[1] == "00" ) {
			$record = substr($row[0],6);
		} else {
			$record =  substr($row[0],3);
		}
	} else {
		$record = $row[0];
	}
	$show10 = $record;
}
$show11="";
$sql = mysqli_query($splink,"Select STANDARD from COMPETITIONITEM where keyid=\"12\"");
while ($row = mysqli_fetch_row($sql)){
	$temp = explode(":",$row[0]);
	if ($temp[0] == "00") {
		if ($temp[1] == "00" ) {
			$record = substr($row[0],6);
		} else {
			$record =  substr($row[0],3);
		}
	} else {
		$record = $row[0];
	}
	$show11 = $record;
}
$show20="";
$sql = mysqli_query($splink,"Select STANDARD from COMPETITIONITEM where keyid=\"19\"");
while ($row = mysqli_fetch_row($sql)){
	$temp = explode(":",$row[0]);
	if ($temp[0] == "00") {
		if ($temp[1] == "00" ) {
			$record = substr($row[0],6);
		} else {
			$record =  substr($row[0],3);
		}
	} else {
		$record = $row[0];
	}
	$show20 = $record;
}
$show40="";
$sql = mysqli_query($splink,"Select STANDARD from COMPETITIONITEM where keyid=\"28\"");
while ($row = mysqli_fetch_row($sql)){
	$temp = explode(":",$row[0]);
	if ($temp[0] == "00") {
		if ($temp[1] == "00" ) {
			$record = substr($row[0],6);
		} else {
			$record =  substr($row[0],3);
		}
	} else {
		$record = $row[0];
	}
	$show40 = $record;
}
$show80="";
$sql = mysqli_query($splink,"Select STANDARD from COMPETITIONITEM where keyid=\"34\"");
while ($row = mysqli_fetch_row($sql)){
	$temp = explode(":",$row[0]);
	if ($temp[0] == "00") {
		if ($temp[1] == "00" ) {
			$record = substr($row[0],6);
		} else {
			$record =  substr($row[0],3);
		}
	} else {
		$record = $row[0];
	}
	$show80 = $record;
}
$show150="";
$sql = mysqli_query($splink,"Select STANDARD from COMPETITIONITEM where keyid=\"13\"");
while ($row = mysqli_fetch_row($sql)){
	$temp = explode(":",$row[0]);
	if ($temp[0] == "00") {
		if ($temp[1] == "00" ) {
			$record = substr($row[0],6);
		} else {
			$record =  substr($row[0],3);
		}
	} else {
		$record = $row[0];
	}
	$show150 = $record;
}
$show300="";
$sql = mysqli_query($splink,"Select STANDARD from COMPETITIONITEM where keyid=\"25\"");
while ($row = mysqli_fetch_row($sql)){
	$temp = explode(":",$row[0]);
	if ($temp[0] == "00") {
		if ($temp[1] == "00" ) {
			$record = substr($row[0],6);
		} else {
			$record =  substr($row[0],3);
		}
	} else {
		$record = $row[0];
	}
	$show300 = $record;
}
$tabletrackstandard ->	addRow(400);
$tabletrackstandard ->	addCell(1000,$borderbot10lef20)->addText("男甲",$font14,$paracenter);
$tabletrackstandard ->	addCell(1000,$borderbot10lef10)->addText($show10,$font14,$paracenter);
$tabletrackstandard ->	addCell(1000,$borderbot10lef10)->addText($show11,$font14,$paracenter);
$tabletrackstandard ->	addCell(1000,$borderbot10lef10)->addText($show20,$font14,$paracenter);
$tabletrackstandard ->	addCell(1000,$borderbot10lef10)->addText($show40,$font14,$paracenter);
$tabletrackstandard ->	addCell(1000,$borderbot10lef10)->addText($show80,$font14,$paracenter);
$tabletrackstandard ->	addCell(1000,$borderbot10lef10)->addText($show150,$font14,$paracenter);
$tabletrackstandard ->	addCell(1000,$borderbot10lef10rig20)->addText($show300,$font14,$paracenter);

$show10="";
$sql = mysqli_query($splink,"Select STANDARD from COMPETITIONITEM where keyid=\"3\"");
while ($row = mysqli_fetch_row($sql)){
	$temp= explode(":",$row[0]);
	if ($temp[0] == "00") {
		if ($temp[1] ==  "00") {
			$show = substr($row[0],6);
		} else {
			$show = substr($row[0],3);
		}
	} else {
		$show = $row[0];
	}
	$show10 = $show;
}
$show11="";
$sql = mysqli_query($splink,"Select STANDARD from COMPETITIONITEM where keyid=\"8\"");
while ($row = mysqli_fetch_row($sql)){
	$temp= explode(":",$row[0]);
	if ($temp[0] == "00") {
		if ($temp[1] ==  "00") {
			$show = substr($row[0],6);
		} else {
			$show = substr($row[0],3);
		}
	} else {
		$show = $row[0];
	}
	$show11 = $show;
}
$show20="";
$sql = mysqli_query($splink,"Select STANDARD from COMPETITIONITEM where keyid=\"21\"");
while ($row = mysqli_fetch_row($sql)){
	$temp= explode(":",$row[0]);
	if ($temp[0] == "00") {
		if ($temp[1] ==  "00") {
			$show = substr($row[0],6);
		} else {
			$show = substr($row[0],3);
		}
	} else {
		$show = $row[0];
	}
	$show20 = $show;
}
$show40="";
$sql = mysqli_query($splink,"Select STANDARD from COMPETITIONITEM where keyid=\"30\"");
while ($row = mysqli_fetch_row($sql)){
	$temp= explode(":",$row[0]);
	if ($temp[0] == "00") {
		if ($temp[1] ==  "00") {
			$show = substr($row[0],6);
		} else {
			$show = substr($row[0],3);
		}
	} else {
		$show = $row[0];
	}
	$show40 = $show;
}
$show80="";
$sql = mysqli_query($splink,"Select STANDARD from COMPETITIONITEM where keyid=\"36\"");
while ($row = mysqli_fetch_row($sql)){
	$temp= explode(":",$row[0]);
	if ($temp[0] == "00") {
		if ($temp[1] ==  "00") {
			$show = substr($row[0],6);
		} else {
			$show = substr($row[0],3);
		}
	} else {
		$show = $row[0];
	}
	$show80 = $show;
}
$show150="";
$sql = mysqli_query($splink,"Select STANDARD from COMPETITIONITEM where keyid=\"15\"");
while ($row = mysqli_fetch_row($sql)){
	$temp= explode(":",$row[0]);
	if ($temp[0] == "00") {
		if ($temp[1] ==  "00") {
			$show = substr($row[0],6);
		} else {
			$show = substr($row[0],3);
		}
	} else {
		$show = $row[0];
	}
	$show150 = $show;
}
$show300="";
$sql = mysqli_query($splink,"Select STANDARD from COMPETITIONITEM where keyid=\"26\"");
while ($row = mysqli_fetch_row($sql)){
	$temp= explode(":",$row[0]);
	if ($temp[0] == "00") {
		if ($temp[1] ==  "00") {
			$show = substr($row[0],6);
		} else {
			$show = substr($row[0],3);
		}
	} else {
		$show = $row[0];
	}
	$show300 = $show;
}
$tabletrackstandard ->	addRow(400);
$tabletrackstandard ->	addCell(1000,$borderbot10lef20)->addText("男乙",$font14,$paracenter);
$tabletrackstandard ->	addCell(1000,$borderbot10lef10)->addText($show10,$font14,$paracenter);
$tabletrackstandard ->	addCell(1000,$borderbot10lef10)->addText($show11,$font14,$paracenter);
$tabletrackstandard ->	addCell(1000,$borderbot10lef10)->addText($show20,$font14,$paracenter);
$tabletrackstandard ->	addCell(1000,$borderbot10lef10)->addText($show40,$font14,$paracenter);
$tabletrackstandard ->	addCell(1000,$borderbot10lef10)->addText($show80,$font14,$paracenter);
$tabletrackstandard ->	addCell(1000,$borderbot10lef10)->addText($show150,$font14,$paracenter);
$tabletrackstandard ->	addCell(1000,$borderbot10lef10rig20)->addText($show300,$font14,$paracenter);

$show10="";
$sql = mysqli_query($splink,"Select STANDARD from COMPETITIONITEM where keyid=\"5\"");
while ($row = mysqli_fetch_row($sql)){
	$temp= explode(":",$row[0]);
	if ($temp[0] == "00") {
		if ($temp[1] ==  "00") {
			$show = substr($row[0],6);
		} else {
			$show = substr($row[0],3);
		}
	} else {
		$show = $row[0];
	}
	$show10 = $show;
}
$show11="";
$sql = mysqli_query($splink,"Select STANDARD from COMPETITIONITEM where keyid=\"10\"");
while ($row = mysqli_fetch_row($sql)){
	$temp= explode(":",$row[0]);
	if ($temp[0] == "00") {
		if ($temp[1] ==  "00") {
			$show = substr($row[0],6);
		} else {
			$show = substr($row[0],3);
		}
	} else {
		$show = $row[0];
	}
	$show11 = $show;
}
$show20="";
$sql = mysqli_query($splink,"Select STANDARD from COMPETITIONITEM where keyid=\"23\"");
while ($row = mysqli_fetch_row($sql)){
	$temp= explode(":",$row[0]);
	if ($temp[0] == "00") {
		if ($temp[1] ==  "00") {
			$show = substr($row[0],6);
		} else {
			$show = substr($row[0],3);
		}
	} else {
		$show = $row[0];
	}
	$show20 = $show;
}
$show40="";
$sql = mysqli_query($splink,"Select STANDARD from COMPETITIONITEM where keyid=\"32\"");
while ($row = mysqli_fetch_row($sql)){
	$temp= explode(":",$row[0]);
	if ($temp[0] == "00") {
		if ($temp[1] ==  "00") {
			$show = substr($row[0],6);
		} else {
			$show = substr($row[0],3);
		}
	} else {
		$show = $row[0];
	}
	$show40 = $show;
}
$show80="";
$sql = mysqli_query($splink,"Select STANDARD from COMPETITIONITEM where keyid=\"38\"");
while ($row = mysqli_fetch_row($sql)){
	$temp= explode(":",$row[0]);
	if ($temp[0] == "00") {
		if ($temp[1] ==  "00") {
			$show = substr($row[0],6);
		} else {
			$show = substr($row[0],3);
		}
	} else {
		$show = $row[0];
	}
	$show80 = $show;
}
$show150="";
$sql = mysqli_query($splink,"Select STANDARD from COMPETITIONITEM where keyid=\"17\"");
while ($row = mysqli_fetch_row($sql)){
	$temp= explode(":",$row[0]);
	if ($temp[0] == "00") {
		if ($temp[1] ==  "00") {
			$show = substr($row[0],6);
		} else {
			$show = substr($row[0],3);
		}
	} else {
		$show = $row[0];
	}
	$show150 = $show;
}
$show300="";
$sql = mysqli_query($splink,"Select STANDARD from COMPETITIONITEM where keyid=\"27\"");
while ($row = mysqli_fetch_row($sql)){
	$temp= explode(":",$row[0]);
	if ($temp[0] == "00") {
		if ($temp[1] ==  "00") {
			$show = substr($row[0],6);
		} else {
			$show = substr($row[0],3);
		}
	} else {
		$show = $row[0];
	}
	$show300 = $show;
}
$tabletrackstandard ->	addRow(400);
$tabletrackstandard ->	addCell(1000,$borderbot10lef20)->addText("男丙",$font14,$paracenter);
$tabletrackstandard ->	addCell(1000,$borderbot10lef10)->addText($show10,$font14,$paracenter);
$tabletrackstandard ->	addCell(1000,$borderbot10lef10)->addText($show11,$font14,$paracenter);
$tabletrackstandard ->	addCell(1000,$borderbot10lef10)->addText($show20,$font14,$paracenter);
$tabletrackstandard ->	addCell(1000,$borderbot10lef10)->addText($show40,$font14,$paracenter);
$tabletrackstandard ->	addCell(1000,$borderbot10lef10)->addText($show80,$font14,$paracenter);
$tabletrackstandard ->	addCell(1000,$borderbot10lef10)->addText($show150,$font14,$paracenter);
$tabletrackstandard ->	addCell(1000,$borderbot10lef10rig20)->addText($show300,$font14,$paracenter);

$show10="";
$sql = mysqli_query($splink,"Select STANDARD from COMPETITIONITEM where keyid=\"2\"");
while ($row = mysqli_fetch_row($sql)){
	$temp= explode(":",$row[0]);
	if ($temp[0] == "00") {
		if ($temp[1] ==  "00") {
			$show = substr($row[0],6);
		} else {
			$show = substr($row[0],3);
		}
	} else {
		$show = $row[0];
	}
	$show10 = $show;
}
$show11="";
$sql = mysqli_query($splink,"Select STANDARD from COMPETITIONITEM where keyid=\"7\"");
while ($row = mysqli_fetch_row($sql)){
	$temp= explode(":",$row[0]);
	if ($temp[0] == "00") {
		if ($temp[1] ==  "00") {
			$show = substr($row[0],6);
		} else {
			$show = substr($row[0],3);
		}
	} else {
		$show = $row[0];
	}
	$show11 = $show;
}
$show20="";
$sql = mysqli_query($splink,"Select STANDARD from COMPETITIONITEM where keyid=\"20\"");
while ($row = mysqli_fetch_row($sql)){
	$temp= explode(":",$row[0]);
	if ($temp[0] == "00") {
		if ($temp[1] ==  "00") {
			$show = substr($row[0],6);
		} else {
			$show = substr($row[0],3);
		}
	} else {
		$show = $row[0];
	}
	$show20 = $show;
}
$show40="";
$sql = mysqli_query($splink,"Select STANDARD from COMPETITIONITEM where keyid=\"29\"");
while ($row = mysqli_fetch_row($sql)){
	$temp= explode(":",$row[0]);
	if ($temp[0] == "00") {
		if ($temp[1] ==  "00") {
			$show = substr($row[0],6);
		} else {
			$show = substr($row[0],3);
		}
	} else {
		$show = $row[0];
	}
	$show40 = $show;
}
$show80="";
$sql = mysqli_query($splink,"Select STANDARD from COMPETITIONITEM where keyid=\"35\"");
while ($row = mysqli_fetch_row($sql)){
	$temp= explode(":",$row[0]);
	if ($temp[0] == "00") {
		if ($temp[1] ==  "00") {
			$show = substr($row[0],6);
		} else {
			$show = substr($row[0],3);
		}
	} else {
		$show = $row[0];
	}
	$show80 = $show;
}
$show150="";
$sql = mysqli_query($splink,"Select STANDARD from COMPETITIONITEM where keyid=\"14\"");
while ($row = mysqli_fetch_row($sql)){
	$temp= explode(":",$row[0]);
	if ($temp[0] == "00") {
		if ($temp[1] ==  "00") {
			$show = substr($row[0],6);
		} else {
			$show = substr($row[0],3);
		}
	} else {
		$show = $row[0];
	}
	$show150 = $show;
}
$show300="";
$tabletrackstandard ->	addRow(400);
$tabletrackstandard ->	addCell(1000,$borderbot10lef20)->addText("女甲",$font14,$paracenter);
$tabletrackstandard ->	addCell(1000,$borderbot10lef10)->addText($show10,$font14,$paracenter);
$tabletrackstandard ->	addCell(1000,$borderbot10lef10)->addText($show11,$font14,$paracenter);
$tabletrackstandard ->	addCell(1000,$borderbot10lef10)->addText($show20,$font14,$paracenter);
$tabletrackstandard ->	addCell(1000,$borderbot10lef10)->addText($show40,$font14,$paracenter);
$tabletrackstandard ->	addCell(1000,$borderbot10lef10)->addText($show80,$font14,$paracenter);
$tabletrackstandard ->	addCell(1000,$borderbot10lef10)->addText($show150,$font14,$paracenter);
$tabletrackstandard ->	addCell(1000,$borderbot10lef10rig20)->addText($show300,$font14,$paracenter);

$show10="";
$sql = mysqli_query($splink,"Select STANDARD from COMPETITIONITEM where keyid=\"4\"");
while ($row = mysqli_fetch_row($sql)){
	$temp= explode(":",$row[0]);
	if ($temp[0] == "00") {
		if ($temp[1] ==  "00") {
			$show = substr($row[0],6);
		} else {
			$show = substr($row[0],3);
		}
	} else {
		$show = $row[0];
	}
	$show10 = $show;
}
$show11="";
$sql = mysqli_query($splink,"Select STANDARD from COMPETITIONITEM where keyid=\"9\"");
while ($row = mysqli_fetch_row($sql)){
	$temp= explode(":",$row[0]);
	if ($temp[0] == "00") {
		if ($temp[1] ==  "00") {
			$show = substr($row[0],6);
		} else {
			$show = substr($row[0],3);
		}
	} else {
		$show = $row[0];
	}
	$show11 = $show;
}
$show20="";
$sql = mysqli_query($splink,"Select STANDARD from COMPETITIONITEM where keyid=\"22\"");
while ($row = mysqli_fetch_row($sql)){
	$temp= explode(":",$row[0]);
	if ($temp[0] == "00") {
		if ($temp[1] ==  "00") {
			$show = substr($row[0],6);
		} else {
			$show = substr($row[0],3);
		}
	} else {
		$show = $row[0];
	}
	$show20 = $show;
}
$show40="";
$sql = mysqli_query($splink,"Select STANDARD from COMPETITIONITEM where keyid=\"31\"");
while ($row = mysqli_fetch_row($sql)){
	$temp= explode(":",$row[0]);
	if ($temp[0] == "00") {
		if ($temp[1] ==  "00") {
			$show = substr($row[0],6);
		} else {
			$show = substr($row[0],3);
		}
	} else {
		$show = $row[0];
	}
	$show40 = $show;
}
$show80="";
$sql = mysqli_query($splink,"Select STANDARD from COMPETITIONITEM where keyid=\"37\"");
while ($row = mysqli_fetch_row($sql)){
	$temp= explode(":",$row[0]);
	if ($temp[0] == "00") {
		if ($temp[1] ==  "00") {
			$show = substr($row[0],6);
		} else {
			$show = substr($row[0],3);
		}
	} else {
		$show = $row[0];
	}
	$show80 = $show;
}
$show150="";
$sql = mysqli_query($splink,"Select STANDARD from COMPETITIONITEM where keyid=\"16\"");
while ($row = mysqli_fetch_row($sql)){
	$temp= explode(":",$row[0]);
	if ($temp[0] == "00") {
		if ($temp[1] ==  "00") {
			$show = substr($row[0],6);
		} else {
			$show = substr($row[0],3);
		}
	} else {
		$show = $row[0];
	}
	$show150 = $show;
}
$show300="";
$tabletrackstandard ->	addRow(400);
$tabletrackstandard ->	addCell(1000,$borderbot10lef20)->addText("女乙",$font14,$paracenter);
$tabletrackstandard ->	addCell(1000,$borderbot10lef10)->addText($show10,$font14,$paracenter);
$tabletrackstandard ->	addCell(1000,$borderbot10lef10)->addText($show11,$font14,$paracenter);
$tabletrackstandard ->	addCell(1000,$borderbot10lef10)->addText($show20,$font14,$paracenter);
$tabletrackstandard ->	addCell(1000,$borderbot10lef10)->addText($show40,$font14,$paracenter);
$tabletrackstandard ->	addCell(1000,$borderbot10lef10)->addText($show80,$font14,$paracenter);
$tabletrackstandard ->	addCell(1000,$borderbot10lef10)->addText($show150,$font14,$paracenter);
$tabletrackstandard ->	addCell(1000,$borderbot10lef10rig20)->addText($show300,$font14,$paracenter);

$show10="";
$sql = mysqli_query($splink,"Select STANDARD from COMPETITIONITEM where keyid=\"6\"");
while ($row = mysqli_fetch_row($sql)){
	$temp= explode(":",$row[0]);
	if ($temp[0] == "00") {
		if ($temp[1] ==  "00") {
			$show = substr($row[0],6);
		} else {
			$show = substr($row[0],3);
		}
	} else {
		$show = $row[0];
	}
	$show10 = $show;
}
$show11="";
$sql = mysqli_query($splink,"Select STANDARD from COMPETITIONITEM where keyid=\"11\"");
while ($row = mysqli_fetch_row($sql)){
	$temp= explode(":",$row[0]);
	if ($temp[0] == "00") {
		if ($temp[1] ==  "00") {
			$show = substr($row[0],6);
		} else {
			$show = substr($row[0],3);
		}
	} else {
		$show = $row[0];
	}
	$show11 = $show;
}
$show20="";
$sql = mysqli_query($splink,"Select STANDARD from COMPETITIONITEM where keyid=\"24\"");
while ($row = mysqli_fetch_row($sql)){
	$temp= explode(":",$row[0]);
	if ($temp[0] == "00") {
		if ($temp[1] ==  "00") {
			$show = substr($row[0],6);
		} else {
			$show = substr($row[0],3);
		}
	} else {
		$show = $row[0];
	}
	$show20 = $show;
}
$show40="";
$sql = mysqli_query($splink,"Select STANDARD from COMPETITIONITEM where keyid=\"33\"");
while ($row = mysqli_fetch_row($sql)){
	$temp= explode(":",$row[0]);
	if ($temp[0] == "00") {
		if ($temp[1] ==  "00") {
			$show = substr($row[0],6);
		} else {
			$show = substr($row[0],3);
		}
	} else {
		$show = $row[0];
	}
	$show40 = $show;
}
$show80="";
$sql = mysqli_query($splink,"Select STANDARD from COMPETITIONITEM where keyid=\"39\"");
while ($row = mysqli_fetch_row($sql)){
	$temp= explode(":",$row[0]);
	if ($temp[0] == "00") {
		if ($temp[1] ==  "00") {
			$show = substr($row[0],6);
		} else {
			$show = substr($row[0],3);
		}
	} else {
		$show = $row[0];
	}
	$show80 = $show;
}
$show150="";
$sql = mysqli_query($splink,"Select STANDARD from COMPETITIONITEM where keyid=\"18\"");
while ($row = mysqli_fetch_row($sql)){
	$temp= explode(":",$row[0]);
	if ($temp[0] == "00") {
		if ($temp[1] ==  "00") {
			$show = substr($row[0],6);
		} else {
			$show = substr($row[0],3);
		}
	} else {
		$show = $row[0];
	}
	$show150 = $show;
}
$show300="";
$tabletrackstandard ->	addRow(400);
$tabletrackstandard ->	addCell(1000,$borderbot20lef20)->addText("女丙",$font14,$paracenter);
$tabletrackstandard ->	addCell(1000,$borderbot20lef10)->addText($show10,$font14,$paracenter);
$tabletrackstandard ->	addCell(1000,$borderbot20lef10)->addText($show11,$font14,$paracenter);
$tabletrackstandard ->	addCell(1000,$borderbot20lef10)->addText($show20,$font14,$paracenter);
$tabletrackstandard ->	addCell(1000,$borderbot20lef10)->addText($show40,$font14,$paracenter);
$tabletrackstandard ->	addCell(1000,$borderbot20lef10)->addText($show80,$font14,$paracenter);
$tabletrackstandard ->	addCell(1000,$borderbot20lef10)->addText($show150,$font14,$paracenter);
$tabletrackstandard ->	addCell(1000,$borderbot20lef10rig20)->addText($show300,$font14,$paracenter);

$section->addText("註：各參賽同學如能達標，可獲加一分社分。",$font14);
$section->addPageBreak();

//運動員須知
$section-> addText($company,$bold18,$paracenter);
$section-> addText($sportdayname,$bold18,$paracenter);
$section-> addText('運動員須知', $bold14singleline, $paracenter);
$section-> addTextBreak();
/*
$akliststyle = array('listType' => \PhpOffice\PhpWord\Style\ListItem::TYPE_NUMBER);
*/
$akliststyle="multilevel";
$phpWord->addNumberingStyle(
	$akliststyle,
				 array('type'=>'multilevel',
						'levels' => array(
							array('format' => 'decimal', 'text' => '%1.', 'left' => 360, 'hanging' => 360, 'tabPos' => 360),
            				array('format' => 'lowerRoman', 'text' => '%2.', 'left' => 720, 'hanging' => 360, 'tabPos' => 720),
				        )
			    )
);
$section-> addListItem('比賽： 採取香港業餘田徑總會之最新業餘田徑規則。',0,$font12,$akliststyle,null);
$section-> addListItem('報名： 每運動員最多參加三項個人項目。在三項中必須包括有田賽及徑賽項目。接力不計算在內。',0,$font12,$akliststyle);
$section-> addListItem('田賽： 除跳高外，各項田賽之運動員有兩次試跳或試擲，取成績最好之前八名進入決賽，繼續跳或擲兩次以定名次。（註：在田賽項目中初賽紀錄也計算在內）',0,$font12,$akliststyle);
$section-> addListItem('徑賽： 不論初賽組數多少，各項徑賽均取最佳之前八名進入決賽。若初賽時間相同，則以抽籤決定。',0,$font12,$akliststyle);
$section-> addListItem('運動員如遇田賽及徑賽時間相衝突時，可以先向田賽裁判請假，待參加徑賽完畢後始行繼續田賽項目。其補賽之次序及次數依當時比賽之情形下進行，惟請假時間不能超過初賽或決賽之比賽二次後，跳高則須依當時比賽之高度進行。',0,$font12,$akliststyle);
$section-> addListItem('運動員必須將號碼布用扣針扣於運動衣胸前，不能出示號碼布者不得出賽。',0,$font12,$akliststyle);
$section-> addListItem('運動員不得代替他人比賽，否則取消其比賽資格及其社於該項比賽之全部得分。',0,$font12,$akliststyle);
$section-> addListItem('運動員須注意宜佈員之宜佈，各項比賽於第一次召集時須立即到召集處聽候指引員點名。在最後召集時，兩次呼名不應者，即失去該項比賽權。點名完畢，由指引員帶領下，方可入場。',0,$font12,$akliststyle);
$section-> addListItem('非參加該項比賽的運動員，一律不得進入比賽場地，違者將會被取消其比賽資格。',0,$font12,$akliststyle);
$section-> addListItem('運動員於參加某項比賽完畢後，必須立即退出場外，不得滯留，違者賽會得取消其比賽資格。',0,$font12,$akliststyle);
$section-> addListItem('如個人項目報名人數少於三人或接力賽報名隊伍少於三隊，則該項比賽將會被取消。',0,$font12,$akliststyle);
$section-> addListItem('計分方法：',0,$font12,$akliststyle);
$section-> addListItem('凡參加一單項項目即可得一分，餘此類推。',1,$font12,$akliststyle);
$section-> addListItem('凡於一單項項目達到標準可得一分，餘此類推。',1,$font12,$akliststyle);
$section-> addListItem('運動員如臨場棄權而沒有充份理由，一律當作欠缺體育精神，初賽棄權每一單項扣社總分一分。',1,$font12,$akliststyle);
$section-> addListItem('個人項目依決賽後名次，由第一至第八名得分為9、7、6、5、4、3、2、1分。如運動員於決賽時棄權，則不能獲得分數。',1,$font12,$akliststyle);
$section-> addListItem('分組個人全場冠軍以個人獎牌數目計算，先計算金牌，然後銀牌，最後銅牌，如遇獎牌數目及獎項一樣，則以個人分數計算。',1,$font12,$akliststyle);
$section-> addListItem('接力項目由第一至第四名得分為18、14、12、10…… 餘此類推。而棄權隊伍則不能獲得分數。',1,$font12,$akliststyle);
$section-> addListItem('破紀錄項目將獲加兩分獎勵分給個人（或接力隊）及社總成績。',1,$font12,$akliststyle);
$section-> addListItem('獎品：',0,$font12,$akliststyle);
$section-> addListItem('分組田徑項目冠、亞、季軍三名。',1,$font12,$akliststyle);
$section-> addListItem('男、女子分組個人全場冠軍。',1,$font12,$akliststyle);
$section-> addListItem('男、女子分組社際全場冠軍。',1,$font12,$akliststyle);
$section-> addListItem('社際全場總冠軍。',1,$font12,$akliststyle);
$section-> addListItem('上訴：',0,$font12,$akliststyle);
$section-> addListItem('如規則上未有言明者，以裁判決定為準。',1,$font12,$akliststyle);
$section-> addListItem('如有上訴，由社長於成績宣佈後十五分鐘內以書面向有關裁判提出(即田賽總裁判，徑賽總裁判)。',1,$font12,$akliststyle);
$section-> addListItem('經裁判之決定即為終決。',1,$font12,$akliststyle);
$section-> addListItem('備註： 以上各項如有未盡之處，賽會有權作出刪改或修改。',0,$font12,$akliststyle);

$section->addPageBreak();

//比賽紀錄
$section-> addText($company,$bold18,$paracenter);
$section-> addText($sportdayname,$bold18,$paracenter);
$section-> addText('各項比賽紀錄', $bold14singleline, $paracenter);
$section-> addTextBreak();
$section-> addText('男子紀錄',$font14u);
$tablebestrecordM = $section->addTable($contentTableStyle);
$tablebestrecordM -> addRow(300);
$tablebestrecordM -> addCell(1000,$borderall20) -> addText('項目',$font12,$paracenter);
$tablebestrecordM -> addCell(3000,$borderall20) -> addText('甲組',$font12,$paracenter);
$tablebestrecordM -> addCell(3000,$borderall20) -> addText('乙組',$font12,$paracenter);
$tablebestrecordM -> addCell(3000,$borderall20) -> addText('丙組',$font12,$paracenter);
$tablebestrecordM -> addRow(300);
$tablebestrecordM -> addCell(1000,$borderbot10lef20) -> addText('100M',$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"1\"");
while ($row= mysqli_fetch_row($sql)){
	$temp = explode(":",$row[3]);
	if ($temp[0] == "00") {
		if ($temp[1] == "00" ) {
			$record = substr($row[3],6);
		} else {
			$record =  substr($row[3],3);
		}
	} else {
		$record = $row[3];
	}
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$record."　(".$gyear.")";
}
$tablebestrecordM -> addCell(3000,$borderbot10lef20) -> addText($show,$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"3\"");
while ($row= mysqli_fetch_row($sql)){
	$temp = explode(":",$row[3]);
	if ($temp[0] == "00") {
		if ($temp[1] == "00" ) {
			$record = substr($row[3],6);
		} else {
			$record =  substr($row[3],3);
		}
	} else {
		$record = $row[3];
	}
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$record."　(".$gyear.")";
}
$tablebestrecordM -> addCell(3000,$borderbot10lef20) -> addText($show,$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"5\"");
while ($row= mysqli_fetch_row($sql)){
	$temp = explode(":",$row[3]);
	if ($temp[0] == "00") {
		if ($temp[1] == "00" ) {
			$record = substr($row[3],6);
		} else {
			$record =  substr($row[3],3);
		}
	} else {
		$record = $row[3];
	}
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$record."　(".$gyear.")";
}
$tablebestrecordM -> addCell(3000,$borderbot10lef20rig20) -> addText($show,$font10,$paracenter);

$tablebestrecordM -> addRow(300);
$tablebestrecordM -> addCell(1000,$borderbot10lef20rig20) -> addText('200M',$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"19\"");
while ($row= mysqli_fetch_row($sql)){
	$temp = explode(":",$row[3]);
	if ($temp[0] == "00") {
		if ($temp[1] == "00" ) {
			$record = substr($row[3],6);
		} else {
			$record =  substr($row[3],3);
		}
	} else {
		$record = $row[3];
	}
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$record."　(".$gyear.")";
}
$tablebestrecordM -> addCell(3000,$borderbot10lef20) -> addText($show,$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"21\"");
while ($row= mysqli_fetch_row($sql)){
	$temp = explode(":",$row[3]);
	if ($temp[0] == "00") {
		if ($temp[1] == "00" ) {
			$record = substr($row[3],6);
		} else {
			$record =  substr($row[3],3);
		}
	} else {
		$record = $row[3];
	}
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$record."　(".$gyear.")";
}
$tablebestrecordM -> addCell(3000,$borderbot10lef20) -> addText($show,$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"23\"");
while ($row= mysqli_fetch_row($sql)){
	$temp = explode(":",$row[3]);
	if ($temp[0] == "00") {
		if ($temp[1] == "00" ) {
			$record = substr($row[3],6);
		} else {
			$record =  substr($row[3],3);
		}
	} else {
		$record = $row[3];
	}
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$record."　(".$gyear.")";
}
$tablebestrecordM -> addCell(3000,$borderbot10lef20rig20) -> addText($show,$font10,$paracenter);

$tablebestrecordM -> addRow(300);
$tablebestrecordM -> addCell(1000,$borderbot10lef20rig20) -> addText('400M',$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"28\"");
while ($row= mysqli_fetch_row($sql)){
	$temp = explode(":",$row[3]);
	if ($temp[0] == "00") {
		if ($temp[1] == "00" ) {
			$record = substr($row[3],6);
		} else {
			$record =  substr($row[3],3);
		}
	} else {
		$record = $row[3];
	}
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$record."　(".$gyear.")";
}
$tablebestrecordM -> addCell(3000,$borderbot10lef20) -> addText($show,$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"30\"");
while ($row= mysqli_fetch_row($sql)){
	$temp = explode(":",$row[3]);
	if ($temp[0] == "00") {
		if ($temp[1] == "00" ) {
			$record = substr($row[3],6);
		} else {
			$record =  substr($row[3],3);
		}
	} else {
		$record = $row[3];
	}
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$record."　(".$gyear.")";
}
$tablebestrecordM -> addCell(3000,$borderbot10lef20) -> addText($show,$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"32\"");
while ($row= mysqli_fetch_row($sql)){
	$temp = explode(":",$row[3]);
	if ($temp[0] == "00") {
		if ($temp[1] == "00" ) {
			$record = substr($row[3],6);
		} else {
			$record =  substr($row[3],3);
		}
	} else {
		$record = $row[3];
	}
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$record."　(".$gyear.")";
}
$tablebestrecordM -> addCell(3000,$borderbot10lef20rig20) -> addText($show,$font10,$paracenter);

$tablebestrecordM -> addRow(300);
$tablebestrecordM -> addCell(1000,$borderbot10lef20rig20) -> addText('800M',$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"34\"");
while ($row= mysqli_fetch_row($sql)){
	$temp = explode(":",$row[3]);
	if ($temp[0] == "00") {
		if ($temp[1] == "00" ) {
			$record = substr($row[3],6);
		} else {
			$record =  substr($row[3],3);
		}
	} else {
		$record = $row[3];
	}
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$record."　(".$gyear.")";
}
$tablebestrecordM -> addCell(3000,$borderbot10lef20) -> addText($show,$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"36\"");
while ($row= mysqli_fetch_row($sql)){
	$temp = explode(":",$row[3]);
	if ($temp[0] == "00") {
		if ($temp[1] == "00" ) {
			$record = substr($row[3],6);
		} else {
			$record =  substr($row[3],3);
		}
	} else {
		$record = $row[3];
	}
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$record."　(".$gyear.")";
}
$tablebestrecordM -> addCell(3000,$borderbot10lef20) -> addText($show,$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"38\"");
while ($row= mysqli_fetch_row($sql)){
	$temp = explode(":",$row[3]);
	if ($temp[0] == "00") {
		if ($temp[1] == "00" ) {
			$record = substr($row[3],6);
		} else {
			$record =  substr($row[3],3);
		}
	} else {
		$record = $row[3];
	}
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$record."　(".$gyear.")";
}
$tablebestrecordM -> addCell(3000,$borderbot10lef20rig20) -> addText($show,$font10,$paracenter);

$tablebestrecordM -> addRow(300);
$tablebestrecordM -> addCell(1000,$borderbot10lef20rig20) -> addText('1500M',$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"13\"");
while ($row= mysqli_fetch_row($sql)){
	$temp = explode(":",$row[3]);
	if ($temp[0] == "00") {
		if ($temp[1] == "00" ) {
			$record = substr($row[3],6);
		} else {
			$record =  substr($row[3],3);
		}
	} else {
		$record = $row[3];
	}
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$record."　(".$gyear.")";
}
$tablebestrecordM -> addCell(3000,$borderbot10lef20) -> addText($show,$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"15\"");
while ($row= mysqli_fetch_row($sql)){
	$temp = explode(":",$row[3]);
	if ($temp[0] == "00") {
		if ($temp[1] == "00" ) {
			$record = substr($row[3],6);
		} else {
			$record =  substr($row[3],3);
		}
	} else {
		$record = $row[3];
	}
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$record."　(".$gyear.")";
}
$tablebestrecordM -> addCell(3000,$borderbot10lef20) -> addText($show,$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"17\"");
while ($row= mysqli_fetch_row($sql)){
	$temp = explode(":",$row[3]);
	if ($temp[0] == "00") {
		if ($temp[1] == "00" ) {
			$record = substr($row[3],6);
		} else {
			$record =  substr($row[3],3);
		}
	} else {
		$record = $row[3];
	}
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$record."　(".$gyear.")";
}
$tablebestrecordM -> addCell(3000,$borderbot10lef20rig20) -> addText($show,$font10,$paracenter);

$tablebestrecordM -> addRow(300);
$tablebestrecordM -> addCell(1000,$borderbot10lef20rig20) -> addText('3000M',$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"25\"");
while ($row= mysqli_fetch_row($sql)){
	$temp = explode(":",$row[3]);
	if ($temp[0] == "00") {
		if ($temp[1] == "00" ) {
			$record = substr($row[3],6);
		} else {
			$record =  substr($row[3],3);
		}
	} else {
		$record = $row[3];
	}
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$record."　(".$gyear.")";
}
$tablebestrecordM -> addCell(3000,$borderbot10lef20) -> addText($show,$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"26\"");
while ($row= mysqli_fetch_row($sql)){
	$temp = explode(":",$row[3]);
	if ($temp[0] == "00") {
		if ($temp[1] == "00" ) {
			$record = substr($row[3],6);
		} else {
			$record =  substr($row[3],3);
		}
	} else {
		$record = $row[3];
	}
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$record."　(".$gyear.")";
}
$tablebestrecordM -> addCell(3000,$borderbot10lef20) -> addText($show,$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"27\"");
while ($row= mysqli_fetch_row($sql)){
	$temp = explode(":",$row[3]);
	if ($temp[0] == "00") {
		if ($temp[1] == "00" ) {
			$record = substr($row[3],6);
		} else {
			$record =  substr($row[3],3);
		}
	} else {
		$record = $row[3];
	}
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$record."　(".$gyear.")";
}
$tablebestrecordM -> addCell(3000,$borderbot10lef20rig20) -> addText($show,$font10,$paracenter);

$tablebestrecordM -> addRow(300);
$tablebestrecordM -> addCell(1000,$borderbot10lef20rig20) -> addText('100M欄',$font10,$paracenter);
$show="";
$tablebestrecordM -> addCell(3000,$borderbot10lef20) -> addText($show,$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"8\"");
while ($row= mysqli_fetch_row($sql)){
	$temp = explode(":",$row[3]);
	if ($temp[0] == "00") {
		if ($temp[1] == "00" ) {
			$record = substr($row[3],6);
		} else {
			$record =  substr($row[3],3);
		}
	} else {
		$record = $row[3];
	}
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$record."　(".$gyear.")";
}
$tablebestrecordM -> addCell(3000,$borderbot10lef20) -> addText($show,$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"10\"");
while ($row= mysqli_fetch_row($sql)){
	$temp = explode(":",$row[3]);
	if ($temp[0] == "00") {
		if ($temp[1] == "00" ) {
			$record = substr($row[3],6);
		} else {
			$record =  substr($row[3],3);
		}
	} else {
		$record = $row[3];
	}
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$record."　(".$gyear.")";
}
$tablebestrecordM -> addCell(3000,$borderbot10lef20rig20) -> addText($show,$font10,$paracenter);
$tablebestrecordM -> addRow(300);
$tablebestrecordM -> addCell(1000,$borderbot10lef20rig20) -> addText('110M欄',$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"12\"");
while ($row= mysqli_fetch_row($sql)){
	$temp = explode(":",$row[3]);
	if ($temp[0] == "00") {
		if ($temp[1] == "00" ) {
			$record = substr($row[3],6);
		} else {
			$record =  substr($row[3],3);
		}
	} else {
		$record = $row[3];
	}
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$record."　(".$gyear.")";
}
$tablebestrecordM -> addCell(3000,$borderbot10lef20) -> addText($show,$font10,$paracenter);
$show="";
$tablebestrecordM -> addCell(3000,$borderbot10lef20) -> addText($show,$font10,$paracenter);
$show="";
$tablebestrecordM -> addCell(3000,$borderbot10lef20rig20) -> addText($show,$font10,$paracenter);

$tablebestrecordM -> addRow(300);
$tablebestrecordM -> addCell(1000,$borderbot10lef20rig20) -> addText('跳高',$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"45\"");
while ($row= mysqli_fetch_row($sql)){
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$row[3]."M　(".$gyear.")";
}
$tablebestrecordM -> addCell(3000,$borderbot10lef20) -> addText($show,$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"47\"");
while ($row= mysqli_fetch_row($sql)){
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$row[3]."M　(".$gyear.")";
}
$tablebestrecordM -> addCell(3000,$borderbot10lef20) -> addText($show,$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"49\"");
while ($row= mysqli_fetch_row($sql)){
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$row[3]."M　(".$gyear.")";
}
$tablebestrecordM -> addCell(3000,$borderbot10lef20rig20) -> addText($show,$font10,$paracenter);

$tablebestrecordM -> addRow(300);
$tablebestrecordM -> addCell(1000,$borderbot10lef20rig20) -> addText('跳遠',$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"67\"");
while ($row= mysqli_fetch_row($sql)){
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$row[3]."M　(".$gyear.")";
}
$tablebestrecordM -> addCell(3000,$borderbot10lef20) -> addText($show,$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"69\"");
while ($row= mysqli_fetch_row($sql)){
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$row[3]."M　(".$gyear.")";
}
$tablebestrecordM -> addCell(3000,$borderbot10lef20) -> addText($show,$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"71\"");
while ($row= mysqli_fetch_row($sql)){
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$row[3]."M　(".$gyear.")";
}
$tablebestrecordM -> addCell(3000,$borderbot10lef20rig20) -> addText($show,$font10,$paracenter);

$tablebestrecordM -> addRow(300);
$tablebestrecordM -> addCell(1000,$borderbot10lef20rig20) -> addText('鉛球',$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"73\"");
while ($row= mysqli_fetch_row($sql)){
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$row[3]."M　(".$gyear.")";
}
$tablebestrecordM -> addCell(3000,$borderbot10lef20) -> addText($show,$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"75\"");
while ($row= mysqli_fetch_row($sql)){
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$row[3]."M　(".$gyear.")";
}
$tablebestrecordM -> addCell(3000,$borderbot10lef20) -> addText($show,$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"77\"");
while ($row= mysqli_fetch_row($sql)){
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$row[3]."M　(".$gyear.")";
}
$tablebestrecordM -> addCell(3000,$borderbot10lef20rig20) -> addText($show,$font10,$paracenter);

$tablebestrecordM -> addRow(300);
$tablebestrecordM -> addCell(1000,$borderbot10lef20rig20) -> addText('鐵餅',$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"41\"");
while ($row= mysqli_fetch_row($sql)){
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$row[3]."M　(".$gyear.")";
}
$tablebestrecordM -> addCell(3000,$borderbot10lef20) -> addText($show,$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"43\"");
while ($row= mysqli_fetch_row($sql)){
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$row[3]."M　(".$gyear.")";
}
$tablebestrecordM -> addCell(3000,$borderbot10lef20) -> addText($show,$font10,$paracenter);
$show="";
$tablebestrecordM -> addCell(3000,$borderbot10lef20rig20) -> addText($show,$font10,$paracenter);

$tablebestrecordM -> addRow(300);
$tablebestrecordM -> addCell(1000,$borderbot10lef20rig20) -> addText('標槍',$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"63\"");
while ($row= mysqli_fetch_row($sql)){
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$row[3]."M　(".$gyear.")";
}
$tablebestrecordM -> addCell(3000,$borderbot10lef20) -> addText($show,$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"65\"");
while ($row= mysqli_fetch_row($sql)){
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$row[3]."M　(".$gyear.")";
}
$tablebestrecordM -> addCell(3000,$borderbot10lef20) -> addText($show,$font10,$paracenter);
$show="";
$tablebestrecordM -> addCell(3000,$borderbot10lef20rig20) -> addText($show,$font10,$paracenter);

$tablebestrecordM -> addRow(300);
$tablebestrecordM -> addCell(1000,$borderbot10lef20rig20) -> addText('三級跳',$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"79\"");
while ($row= mysqli_fetch_row($sql)){
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$row[3]."M　(".$gyear.")";
}
$tablebestrecordM -> addCell(3000,$borderbot10lef20) -> addText($show,$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"80\"");
while ($row= mysqli_fetch_row($sql)){
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$row[3]."M　(".$gyear.")";
}
$tablebestrecordM -> addCell(3000,$borderbot10lef20) -> addText($show,$font10,$paracenter);
$show="";
$tablebestrecordM -> addCell(3000,$borderbot10lef20rig20) -> addText($show,$font10,$paracenter);

$tablebestrecordM -> addRow(300);
$tablebestrecordM -> addCell(1000,$borderbot10lef20rig20) -> addText('4X100M',$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"51\"");
while ($row= mysqli_fetch_row($sql)){
	$temp = explode(":",$row[3]);
	if ($temp[0] == "00") {
		if ($temp[1] == "00" ) {
			$record = substr($row[3],6);
		} else {
			$record =  substr($row[3],3);
		}
	} else {
		$record = $row[3];
	}
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$record."　(".$gyear.")";
}
$tablebestrecordM -> addCell(3000,$borderbot10lef20) -> addText($show,$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"53\"");
while ($row= mysqli_fetch_row($sql)){
	$temp = explode(":",$row[3]);
	if ($temp[0] == "00") {
		if ($temp[1] == "00" ) {
			$record = substr($row[3],6);
		} else {
			$record =  substr($row[3],3);
		}
	} else {
		$record = $row[3];
	}
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$record."　(".$gyear.")";
}
$tablebestrecordM -> addCell(3000,$borderbot10lef20) -> addText($show,$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"55\"");
while ($row= mysqli_fetch_row($sql)){
	$temp = explode(":",$row[3]);
	if ($temp[0] == "00") {
		if ($temp[1] == "00" ) {
			$record = substr($row[3],6);
		} else {
			$record =  substr($row[3],3);
		}
	} else {
		$record = $row[3];
	}
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$record."　(".$gyear.")";
}
$tablebestrecordM -> addCell(3000,$borderbot10lef20rig20) -> addText($show,$font10,$paracenter);

$tablebestrecordM -> addRow(300);
$tablebestrecordM -> addCell(1000,$borderbot20lef20rig20) -> addText('4X400M',$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"57\"");
while ($row= mysqli_fetch_row($sql)){
	$temp = explode(":",$row[3]);
	if ($temp[0] == "00") {
		if ($temp[1] == "00" ) {
			$record = substr($row[3],6);
		} else {
			$record =  substr($row[3],3);
		}
	} else {
		$record = $row[3];
	}
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$record."　(".$gyear.")";
}
$tablebestrecordM -> addCell(3000,$borderbot20lef20) -> addText($show,$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"59\"");
while ($row= mysqli_fetch_row($sql)){
	$temp = explode(":",$row[3]);
	if ($temp[0] == "00") {
		if ($temp[1] == "00" ) {
			$record = substr($row[3],6);
		} else {
			$record =  substr($row[3],3);
		}
	} else {
		$record = $row[3];
	}
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$record."　(".$gyear.")";
}
$tablebestrecordM -> addCell(3000,$borderbot20lef20) -> addText($show,$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"61\"");
while ($row= mysqli_fetch_row($sql)){
	$temp = explode(":",$row[3]);
	if ($temp[0] == "00") {
		if ($temp[1] == "00" ) {
			$record = substr($row[3],6);
		} else {
			$record =  substr($row[3],3);
		}
	} else {
		$record = $row[3];
	}
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$record."　(".$gyear.")";
}
$tablebestrecordM -> addCell(3000,$borderbot20lef20rig20) -> addText($show,$font10,$paracenter);

$section-> addTextBreak();
$section-> addText('女子紀錄',$font14u);
$tablebestrecordF = $section->addTable($contentTableStyle);
$tablebestrecordF -> addRow(300);
$tablebestrecordF -> addCell(1000,$borderall20) -> addText('項目',$font12,$paracenter);
$tablebestrecordF -> addCell(3000,$borderall20) -> addText('甲組',$font12,$paracenter);
$tablebestrecordF -> addCell(3000,$borderall20) -> addText('乙組',$font12,$paracenter);
$tablebestrecordF -> addCell(3000,$borderall20) -> addText('丙組',$font12,$paracenter);
$tablebestrecordF -> addRow(300);
$tablebestrecordF -> addCell(1000,$borderbot10lef20) -> addText('100M',$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"2\"");
while ($row= mysqli_fetch_row($sql)){
	$temp = explode(":",$row[3]);
	if ($temp[0] == "00") {
		if ($temp[1] == "00" ) {
			$record = substr($row[3],6);
		} else {
			$record =  substr($row[3],3);
		}
	} else {
		$record = $row[3];
	}
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$record."　(".$gyear.")";
}
$tablebestrecordF -> addCell(3000,$borderbot10lef20) -> addText($show,$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"4\"");
while ($row= mysqli_fetch_row($sql)){
	$temp = explode(":",$row[3]);
	if ($temp[0] == "00") {
		if ($temp[1] == "00" ) {
			$record = substr($row[3],6);
		} else {
			$record =  substr($row[3],3);
		}
	} else {
		$record = $row[3];
	}
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$record."　(".$gyear.")";
}
$tablebestrecordF -> addCell(3000,$borderbot10lef20) -> addText($show,$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"6\"");
while ($row= mysqli_fetch_row($sql)){
	$temp = explode(":",$row[3]);
	if ($temp[0] == "00") {
		if ($temp[1] == "00" ) {
			$record = substr($row[3],6);
		} else {
			$record =  substr($row[3],3);
		}
	} else {
		$record = $row[3];
	}
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$record."　(".$gyear.")";
}
$tablebestrecordF -> addCell(3000,$borderbot10lef20rig20) -> addText($show,$font10,$paracenter);

$tablebestrecordF -> addRow(300);
$tablebestrecordF -> addCell(1000,$borderbot10lef20rig20) -> addText('200M',$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"20\"");
while ($row= mysqli_fetch_row($sql)){
	$temp = explode(":",$row[3]);
	if ($temp[0] == "00") {
		if ($temp[1] == "00" ) {
			$record = substr($row[3],6);
		} else {
			$record =  substr($row[3],3);
		}
	} else {
		$record = $row[3];
	}
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$record."　(".$gyear.")";
}
$tablebestrecordF -> addCell(3000,$borderbot10lef20) -> addText($show,$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"22\"");
while ($row= mysqli_fetch_row($sql)){
	$temp = explode(":",$row[3]);
	if ($temp[0] == "00") {
		if ($temp[1] == "00" ) {
			$record = substr($row[3],6);
		} else {
			$record =  substr($row[3],3);
		}
	} else {
		$record = $row[3];
	}
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$record."　(".$gyear.")";
}
$tablebestrecordF -> addCell(3000,$borderbot10lef20) -> addText($show,$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"24\"");
while ($row= mysqli_fetch_row($sql)){
	$temp = explode(":",$row[3]);
	if ($temp[0] == "00") {
		if ($temp[1] == "00" ) {
			$record = substr($row[3],6);
		} else {
			$record =  substr($row[3],3);
		}
	} else {
		$record = $row[3];
	}
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$record."　(".$gyear.")";
}
$tablebestrecordF -> addCell(3000,$borderbot10lef20rig20) -> addText($show,$font10,$paracenter);

$tablebestrecordF -> addRow(300);
$tablebestrecordF -> addCell(1000,$borderbot10lef20rig20) -> addText('400M',$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"29\"");
while ($row= mysqli_fetch_row($sql)){
	$temp = explode(":",$row[3]);
	if ($temp[0] == "00") {
		if ($temp[1] == "00" ) {
			$record = substr($row[3],6);
		} else {
			$record =  substr($row[3],3);
		}
	} else {
		$record = $row[3];
	}
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$record."　(".$gyear.")";
}
$tablebestrecordF -> addCell(3000,$borderbot10lef20) -> addText($show,$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"31\"");
while ($row= mysqli_fetch_row($sql)){
	$temp = explode(":",$row[3]);
	if ($temp[0] == "00") {
		if ($temp[1] == "00" ) {
			$record = substr($row[3],6);
		} else {
			$record =  substr($row[3],3);
		}
	} else {
		$record = $row[3];
	}
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$record."　(".$gyear.")";
}
$tablebestrecordF -> addCell(3000,$borderbot10lef20) -> addText($show,$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"33\"");
while ($row= mysqli_fetch_row($sql)){
	$temp = explode(":",$row[3]);
	if ($temp[0] == "00") {
		if ($temp[1] == "00" ) {
			$record = substr($row[3],6);
		} else {
			$record =  substr($row[3],3);
		}
	} else {
		$record = $row[3];
	}
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$record."　(".$gyear.")";
}
$tablebestrecordF -> addCell(3000,$borderbot10lef20rig20) -> addText($show,$font10,$paracenter);

$tablebestrecordF -> addRow(300);
$tablebestrecordF -> addCell(1000,$borderbot10lef20rig20) -> addText('800M',$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"35\"");
while ($row= mysqli_fetch_row($sql)){
	$temp = explode(":",$row[3]);
	if ($temp[0] == "00") {
		if ($temp[1] == "00" ) {
			$record = substr($row[3],6);
		} else {
			$record =  substr($row[3],3);
		}
	} else {
		$record = $row[3];
	}
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$record."　(".$gyear.")";
}
$tablebestrecordF -> addCell(3000,$borderbot10lef20) -> addText($show,$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"37\"");
while ($row= mysqli_fetch_row($sql)){
	$temp = explode(":",$row[3]);
	if ($temp[0] == "00") {
		if ($temp[1] == "00" ) {
			$record = substr($row[3],6);
		} else {
			$record =  substr($row[3],3);
		}
	} else {
		$record = $row[3];
	}
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$record."　(".$gyear.")";
}
$tablebestrecordF -> addCell(3000,$borderbot10lef20) -> addText($show,$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"39\"");
while ($row= mysqli_fetch_row($sql)){
	$temp = explode(":",$row[3]);
	if ($temp[0] == "00") {
		if ($temp[1] == "00" ) {
			$record = substr($row[3],6);
		} else {
			$record =  substr($row[3],3);
		}
	} else {
		$record = $row[3];
	}
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$record."　(".$gyear.")";
}
$tablebestrecordF -> addCell(3000,$borderbot10lef20rig20) -> addText($show,$font10,$paracenter);

$tablebestrecordF -> addRow(300);
$tablebestrecordF -> addCell(1000,$borderbot10lef20rig20) -> addText('1500M',$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"14\"");
while ($row= mysqli_fetch_row($sql)){
	$temp = explode(":",$row[3]);
	if ($temp[0] == "00") {
		if ($temp[1] == "00" ) {
			$record = substr($row[3],6);
		} else {
			$record =  substr($row[3],3);
		}
	} else {
		$record = $row[3];
	}
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$record."　(".$gyear.")";
}
$tablebestrecordF -> addCell(3000,$borderbot10lef20) -> addText($show,$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"16\"");
while ($row= mysqli_fetch_row($sql)){
	$temp = explode(":",$row[3]);
	if ($temp[0] == "00") {
		if ($temp[1] == "00" ) {
			$record = substr($row[3],6);
		} else {
			$record =  substr($row[3],3);
		}
	} else {
		$record = $row[3];
	}
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$record."　(".$gyear.")";
}
$tablebestrecordF -> addCell(3000,$borderbot10lef20) -> addText($show,$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"18\"");
while ($row= mysqli_fetch_row($sql)){
	$temp = explode(":",$row[3]);
	if ($temp[0] == "00") {
		if ($temp[1] == "00" ) {
			$record = substr($row[3],6);
		} else {
			$record =  substr($row[3],3);
		}
	} else {
		$record = $row[3];
	}
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$record."　(".$gyear.")";
}
$tablebestrecordF -> addCell(3000,$borderbot10lef20rig20) -> addText($show,$font10,$paracenter);

$tablebestrecordF -> addRow(300);
$tablebestrecordF -> addCell(1000,$borderbot10lef20rig20) -> addText('100M欄',$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"7\"");
while ($row= mysqli_fetch_row($sql)){
	$temp = explode(":",$row[3]);
	if ($temp[0] == "00") {
		if ($temp[1] == "00" ) {
			$record = substr($row[3],6);
		} else {
			$record =  substr($row[3],3);
		}
	} else {
		$record = $row[3];
	}
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$record."　(".$gyear.")";
}
$tablebestrecordF -> addCell(3000,$borderbot10lef20) -> addText($show,$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"9\"");
while ($row= mysqli_fetch_row($sql)){
	$temp = explode(":",$row[3]);
	if ($temp[0] == "00") {
		if ($temp[1] == "00" ) {
			$record = substr($row[3],6);
		} else {
			$record =  substr($row[3],3);
		}
	} else {
		$record = $row[3];
	}
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$record."　(".$gyear.")";
}
$tablebestrecordF -> addCell(3000,$borderbot10lef20rig20) -> addText($show,$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"11\"");
while ($row= mysqli_fetch_row($sql)){
	$temp = explode(":",$row[3]);
	if ($temp[0] == "00") {
		if ($temp[1] == "00" ) {
			$record = substr($row[3],6);
		} else {
			$record =  substr($row[3],3);
		}
	} else {
		$record = $row[3];
	}
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$record."　(".$gyear.")";
}
$tablebestrecordF -> addCell(3000,$borderbot10lef20) -> addText($show,$font10,$paracenter);

$tablebestrecordF -> addRow(300);
$tablebestrecordF -> addCell(1000,$borderbot10lef20rig20) -> addText('跳高',$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"46\"");
while ($row= mysqli_fetch_row($sql)){
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$row[3]."M　(".$gyear.")";
}
$tablebestrecordF -> addCell(3000,$borderbot10lef20) -> addText($show,$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"48\"");
while ($row= mysqli_fetch_row($sql)){
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$row[3]."M　(".$gyear.")";
}
$tablebestrecordF -> addCell(3000,$borderbot10lef20) -> addText($show,$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"50\"");
while ($row= mysqli_fetch_row($sql)){
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$row[3]."M　(".$gyear.")";
}
$tablebestrecordF -> addCell(3000,$borderbot10lef20rig20) -> addText($show,$font10,$paracenter);

$tablebestrecordF -> addRow(300);
$tablebestrecordF -> addCell(1000,$borderbot10lef20rig20) -> addText('跳遠',$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"68\"");
while ($row= mysqli_fetch_row($sql)){
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$row[3]."M　(".$gyear.")";
}
$tablebestrecordF -> addCell(3000,$borderbot10lef20) -> addText($show,$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"70\"");
while ($row= mysqli_fetch_row($sql)){
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$row[3]."M　(".$gyear.")";
}
$tablebestrecordF -> addCell(3000,$borderbot10lef20) -> addText($show,$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"72\"");
while ($row= mysqli_fetch_row($sql)){
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$row[3]."M　(".$gyear.")";
}
$tablebestrecordF -> addCell(3000,$borderbot10lef20rig20) -> addText($show,$font10,$paracenter);

$tablebestrecordF -> addRow(300);
$tablebestrecordF -> addCell(1000,$borderbot10lef20rig20) -> addText('鉛球',$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"74\"");
while ($row= mysqli_fetch_row($sql)){
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$row[3]."M　(".$gyear.")";
}
$tablebestrecordF -> addCell(3000,$borderbot10lef20) -> addText($show,$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"76\"");
while ($row= mysqli_fetch_row($sql)){
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$row[3]."M　(".$gyear.")";
}
$tablebestrecordF -> addCell(3000,$borderbot10lef20) -> addText($show,$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"78\"");
while ($row= mysqli_fetch_row($sql)){
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$row[3]."M　(".$gyear.")";
}
$tablebestrecordF -> addCell(3000,$borderbot10lef20rig20) -> addText($show,$font10,$paracenter);

$tablebestrecordF -> addRow(300);
$tablebestrecordF -> addCell(1000,$borderbot10lef20rig20) -> addText('鐵餅',$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"42\"");
while ($row= mysqli_fetch_row($sql)){
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$row[3]."M　(".$gyear.")";
}
$tablebestrecordF -> addCell(3000,$borderbot10lef20) -> addText($show,$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"44\"");
while ($row= mysqli_fetch_row($sql)){
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$row[3]."M　(".$gyear.")";
}
$tablebestrecordF -> addCell(3000,$borderbot10lef20) -> addText($show,$font10,$paracenter);
$show="";
$tablebestrecordF -> addCell(3000,$borderbot10lef20rig20) -> addText($show,$font10,$paracenter);

$tablebestrecordF -> addRow(300);
$tablebestrecordF -> addCell(1000,$borderbot10lef20rig20) -> addText('標槍',$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"64\"");
while ($row= mysqli_fetch_row($sql)){
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$row[3]."M　(".$gyear.")";
}
$tablebestrecordF -> addCell(3000,$borderbot10lef20) -> addText($show,$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"66\"");
while ($row= mysqli_fetch_row($sql)){
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$row[3]."M　(".$gyear.")";
}
$tablebestrecordF -> addCell(3000,$borderbot10lef20) -> addText($show,$font10,$paracenter);
$show="";
$tablebestrecordF -> addCell(3000,$borderbot10lef20rig20) -> addText($show,$font10,$paracenter);

$tablebestrecordF -> addRow(300);
$tablebestrecordF -> addCell(1000,$borderbot10lef20rig20) -> addText('4X100M',$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"52\"");
while ($row= mysqli_fetch_row($sql)){
	$temp = explode(":",$row[3]);
	if ($temp[0] == "00") {
		if ($temp[1] == "00" ) {
			$record = substr($row[3],6);
		} else {
			$record =  substr($row[3],3);
		}
	} else {
		$record = $row[3];
	}
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$record."　(".$gyear.")";
}
$tablebestrecordF -> addCell(3000,$borderbot10lef20) -> addText($show,$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"54\"");
while ($row= mysqli_fetch_row($sql)){
	$temp = explode(":",$row[3]);
	if ($temp[0] == "00") {
		if ($temp[1] == "00" ) {
			$record = substr($row[3],6);
		} else {
			$record =  substr($row[3],3);
		}
	} else {
		$record = $row[3];
	}
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$record."　(".$gyear.")";
}
$tablebestrecordF -> addCell(3000,$borderbot10lef20) -> addText($show,$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"56\"");
while ($row= mysqli_fetch_row($sql)){
	$temp = explode(":",$row[3]);
	if ($temp[0] == "00") {
		if ($temp[1] == "00" ) {
			$record = substr($row[3],6);
		} else {
			$record =  substr($row[3],3);
		}
	} else {
		$record = $row[3];
	}
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$record."　(".$gyear.")";
}
$tablebestrecordF -> addCell(3000,$borderbot10lef20rig20) -> addText($show,$font10,$paracenter);

$tablebestrecordF -> addRow(300);
$tablebestrecordF -> addCell(1000,$borderbot20lef20rig20) -> addText('4X400M',$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"58\"");
while ($row= mysqli_fetch_row($sql)){
	$temp = explode(":",$row[3]);
	if ($temp[0] == "00") {
		if ($temp[1] == "00" ) {
			$record = substr($row[3],6);
		} else {
			$record =  substr($row[3],3);
		}
	} else {
		$record = $row[3];
	}
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$record."　(".$gyear.")";
}
$tablebestrecordF -> addCell(3000,$borderbot20lef20) -> addText($show,$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"60\"");
while ($row= mysqli_fetch_row($sql)){
	$temp = explode(":",$row[3]);
	if ($temp[0] == "00") {
		if ($temp[1] == "00" ) {
			$record = substr($row[3],6);
		} else {
			$record =  substr($row[3],3);
		}
	} else {
		$record = $row[3];
	}
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$record."　(".$gyear.")";
}
$tablebestrecordF -> addCell(3000,$borderbot20lef20) -> addText($show,$font10,$paracenter);
$show="";
$sql = mysqli_query($splink,"Select NAME, HOUSE, SCHYEAR, RECORD from BEST_RECORD where COMPETITION_ID=\"62\"");
while ($row= mysqli_fetch_row($sql)){
	$temp = explode(":",$row[3]);
	if ($temp[0] == "00") {
		if ($temp[1] == "00" ) {
			$record = substr($row[3],6);
		} else {
			$record =  substr($row[3],3);
		}
	} else {
		$record = $row[3];
	}
	$nyear = $row[2] + 1;
	$gyear = substr($row[2],-2)."-".substr($nyear,-2);
	$show = $row[0].$row[1]."　".$record."　(".$gyear.")";
}
$tablebestrecordF -> addCell(3000,$borderbot20lef20rig20) -> addText($show,$font10,$paracenter);
$section->addPageBreak();

//工作人員名單
$section-> addText($company,$bold18,$paracenter);
$section-> addText($sportdayname.'工作人員名單',$bold18,$paracenter);
//add columns to the page
$section = $phpWord->addSection(
    array(
        'colsNum'   => 4,
        'colsSpace' => 240,
        'breakType' => 'continuous',
    )
);
//add table to the list
$sql = mysqli_query($splink,"Select sw_id from APPLICATION_STUDENTWORKER where SCHYEAR=\"".$todayschyr."\" AND approved=\"1\" GROUP BY sw_id");
while ($row = mysqli_fetch_row($sql)){
	$swsql = mysqli_query($splink,"Select CH_DES from studentworker where keyid=\"".$row[0]."\"");
	while ($swrow= mysqli_fetch_row($swsql)){
		$swname = $swrow[0];
	}
	$tablename = "tablesw".$row[0];
	$$tablename = $section->addTable($contentTableStyle);
	$$tablename ->addRow(400);
	$$tablename ->addCell(2000,array('gridSpan' =>4,'valign'=>'center', 'borderColor' => '000000', 'borderTopSize' => 15,'borderBottomSize' => 15,'borderLeftSize' => 15,'borderRightSize' => 15))
				-> addText($swname, $font14, $paracenter);
	$x= 1;
	$stsql = mysqli_query($splink,"Select B.CLASSCODE, B.CLASSNO, B.CHNAME from APPLICATION_STUDENTWORKER AS A inner join studentinfo AS B ON A.STUID=B.STUID where A.sw_id=\"".$row[0]."\" AND A.approved=\"1\" ORDER BY B.CLASSCODE, B.CLASSNO");
	while ($strow = mysqli_fetch_row($stsql)){
		$$tablename ->addRow(400);
		$$tablename ->addCell(300,$borderall15) -> addText($x,$font12,$paracenter);
		$$tablename ->addCell(300,$borderall15) -> addText($strow[0],$font12,$paracenter);
		$$tablename ->addCell(300,$borderall15) -> addText($strow[1],$font12,$paracenter);
		$$tablename ->addCell(300,$borderall15) -> addText($strow[2],$font12,$paracenter);
		$x++;
	}
	$section->addTextBreak();
}
$section = $phpWord->addSection(array('breakType' => 'continuous','marginTop' => 500, 'marginBottom' =>500, 'marginLeft'=> 1000, 'marginRight' =>1000));
$section->addPageBreak();


//職員名單
$section-> addText($company,$bold18,$paracenter);
$section-> addText($sportdayname,$bold18,$paracenter);
$section-> addText('職員名單',$bold18,$paracenter);
$section->	addTextBreak();
$section->	addText("榮譽顧問\t：校監鄧英喜太平紳士",$font14,$stafflistTab);
$sql = mysqli_query($splink,"Select STAFF from staffduty where keyid=\"1\"");
while ($row = mysqli_fetch_row($sql)){
	$temp = explode(",",$row[0]);
	$x = 0;
	$showname = "";
	while ($x < sizeof($temp)){
		$tsql = mysqli_query($splink,"Select CH_NAME,stafftitle from teacherinfo where STAFFCODE=\"".$temp[$x]."\"");
		while ($trow = mysqli_fetch_row($tsql)){
			if (in_array($temp[$x],$principal)) {
				$showname .= $trow[0]."校長、";
			} else if (in_array($temp[$x],$vineprincipal)){
				$showname .= $trow[0]."副校長、";
			} else if (in_array($temp[$x],$principalhelp)){
				$showname .= $trow[0]."助理副校長、"; 
			} else {
				$showname .= $trow[0].$trow[1]."、";
			}
		}
		$x++;
	}
	$showname = mb_substr($showname,0,-1);
}
$section->	addText("主席\t：".$showname,$font16,$stafflistTab);
$section->	addText("籌備委員會\t：體育科及課外活動組",$font14,$stafflistTab);
$sql = mysqli_query($splink,"Select STAFF from staffduty where keyid=\"2\"");
while ($row = mysqli_fetch_row($sql)){
	$temp = explode(",",$row[0]);
	$x = 0;
		$showname = "";
	while ($x < sizeof($temp)){
		$tsql = mysqli_query($splink,"Select CH_NAME,stafftitle from teacherinfo where STAFFCODE=\"".$temp[$x]."\"");
		while ($trow = mysqli_fetch_row($tsql)){
			if (in_array($temp[$x],$principal)) {
				$showname .= $trow[0]."校長、";
			} else if (in_array($temp[$x],$vineprincipal)){
				$showname .= $trow[0]."副校長、";
			} else if (in_array($temp[$x],$principalhelp)){
				$showname .= $trow[0]."助理副校長、"; 
			} else {
				$showname .= $trow[0].$trow[1]."、";
			}
		}
		$x++;
	}
	$showname = mb_substr($showname,0,-1);
}
$section->	addText("典禮統籌\t：".$showname,$font14,$stafflistTab);
$sql = mysqli_query($splink,"Select STAFF from staffduty where keyid=\"3\"");
while ($row = mysqli_fetch_row($sql)){
	$temp = explode(",",$row[0]);
	$x = 0;
		$showname = "";
	while ($x < sizeof($temp)){
		$tsql = mysqli_query($splink,"Select CH_NAME,stafftitle from teacherinfo where STAFFCODE=\"".$temp[$x]."\"");
		while ($trow = mysqli_fetch_row($tsql)){
			if (in_array($temp[$x],$principal)) {
				$showname .= $trow[0]."校長、";
			} else if (in_array($temp[$x],$vineprincipal)){
				$showname .= $trow[0]."副校長、";
			} else if (in_array($temp[$x],$principalhelp)){
				$showname .= $trow[0]."助理副校長、"; 
			} else {
				$showname .= $trow[0].$trow[1]."、";
			}
		}
		$x++;
	}
	$showname = mb_substr($showname,0,-1);
}
$section->	addText("總裁判\t：".$showname,$font14,$stafflistTab);

$section->	addTextBreak();
$section->	addText("徑賽",$font16u,$stafflisthead);
$sql = mysqli_query($splink,"Select STAFF from staffduty where keyid=\"4\"");
while ($row = mysqli_fetch_row($sql)){
	$temp = explode(",",$row[0]);
	$x = 0;
		$showname = "";
	while ($x < sizeof($temp)){
		$tsql = mysqli_query($splink,"Select CH_NAME,stafftitle from teacherinfo where STAFFCODE=\"".$temp[$x]."\"");
		while ($trow = mysqli_fetch_row($tsql)){
			if (in_array($temp[$x],$principal)) {
				$showname .= $trow[0]."校長、";
			} else if (in_array($temp[$x],$vineprincipal)){
				$showname .= $trow[0]."副校長、";
			} else if (in_array($temp[$x],$principalhelp)){
				$showname .= $trow[0]."助理副校長、"; 
			} else {
				$showname .= $trow[0].$trow[1]."、";
			}
		}
		$x++;
	}
	$showname = mb_substr($showname,0,-1);
}

$section->	addText("裁判長\t：".$showname,$font14,$stafflistTab);
$sql = mysqli_query($splink,"Select STAFF from staffduty where keyid=\"5\"");
while ($row = mysqli_fetch_row($sql)){
	$temp = explode(",",$row[0]);
	$x = 0;
		$showname = "";
	while ($x < sizeof($temp)){
		$tsql = mysqli_query($splink,"Select CH_NAME,stafftitle from teacherinfo where STAFFCODE=\"".$temp[$x]."\"");
		while ($trow = mysqli_fetch_row($tsql)){
			if (in_array($temp[$x],$principal)) {
				$showname .= $trow[0]."校長、";
			} else if (in_array($temp[$x],$vineprincipal)){
				$showname .= $trow[0]."副校長、";
			} else if (in_array($temp[$x],$principalhelp)){
				$showname .= $trow[0]."助理副校長、"; 
			} else {
				$showname .= $trow[0].$trow[1]."、";
			}
		}
		$x++;
	}
	$showname = mb_substr($showname,0,-1);
}
$section->	addText("召集\t：".$showname,$font14,$stafflistTab);
$sql = mysqli_query($splink,"Select STAFF from staffduty where keyid=\"6\"");
while ($row = mysqli_fetch_row($sql)){
	$temp = explode(",",$row[0]);
	$x = 0;
		$showname = "";
	while ($x < sizeof($temp)){
		$tsql = mysqli_query($splink,"Select CH_NAME,stafftitle from teacherinfo where STAFFCODE=\"".$temp[$x]."\"");
		while ($trow = mysqli_fetch_row($tsql)){
			if (in_array($temp[$x],$principal)) {
				$showname .= $trow[0]."校長、";
			} else if (in_array($temp[$x],$vineprincipal)){
				$showname .= $trow[0]."副校長、";
			} else if (in_array($temp[$x],$principalhelp)){
				$showname .= $trow[0]."助理副校長、"; 
			} else {
				$showname .= $trow[0].$trow[1]."、";
			}
		}
		$x++;
	}
	$showname = mb_substr($showname,0,-1);
}
$section->	addText("指引檢察\t：".$showname,$font14,$stafflistTab);
$sql = mysqli_query($splink,"Select STAFF from staffduty where keyid=\"7\"");
while ($row = mysqli_fetch_row($sql)){
	$temp = explode(",",$row[0]);
	$x = 0;
		$showname = "";
	while ($x < sizeof($temp)){
		$tsql = mysqli_query($splink,"Select CH_NAME,stafftitle from teacherinfo where STAFFCODE=\"".$temp[$x]."\"");
		while ($trow = mysqli_fetch_row($tsql)){
			if (in_array($temp[$x],$principal)) {
				$showname .= $trow[0]."校長、";
			} else if (in_array($temp[$x],$vineprincipal)){
				$showname .= $trow[0]."副校長、";
			} else if (in_array($temp[$x],$principalhelp)){
				$showname .= $trow[0]."助理副校長、"; 
			} else {
				$showname .= $trow[0].$trow[1]."、";
			}
		}
		$x++;
	}
	$showname = mb_substr($showname,0,-1);
}
$section->	addText("發令\t：".$showname,$font14,$stafflistTab);
$sql = mysqli_query($splink,"Select STAFF from staffduty where keyid=\"8\"");
while ($row = mysqli_fetch_row($sql)){
	$temp = explode(",",$row[0]);
	$x = 0;
		$showname = "";
	while ($x < sizeof($temp)){
		$tsql = mysqli_query($splink,"Select CH_NAME,stafftitle from teacherinfo where STAFFCODE=\"".$temp[$x]."\"");
		while ($trow = mysqli_fetch_row($tsql)){
			if (in_array($temp[$x],$principal)) {
				$showname .= $trow[0]."校長、";
			} else if (in_array($temp[$x],$vineprincipal)){
				$showname .= $trow[0]."副校長、";
			} else if (in_array($temp[$x],$principalhelp)){
				$showname .= $trow[0]."助理副校長、"; 
			} else {
				$showname .= $trow[0].$trow[1]."、";
			}
		}
		$x++;
	}
	$showname = mb_substr($showname,0,-1);
}
$section->	addText("計時裁判\t：".$showname,$font14,$stafflistTab);
$sql = mysqli_query($splink,"Select STAFF from staffduty where keyid=\"9\"");
while ($row = mysqli_fetch_row($sql)){
	$temp = explode(",",$row[0]);
	$x = 0;
		$showname = "";
	while ($x < sizeof($temp)){
		$tsql = mysqli_query($splink,"Select CH_NAME,stafftitle from teacherinfo where STAFFCODE=\"".$temp[$x]."\"");
		while ($trow = mysqli_fetch_row($tsql)){
			if (in_array($temp[$x],$principal)) {
				$showname .= $trow[0]."校長、";
			} else if (in_array($temp[$x],$vineprincipal)){
				$showname .= $trow[0]."副校長、";
			} else if (in_array($temp[$x],$principalhelp)){
				$showname .= $trow[0]."助理副校長、"; 
			} else {
				$showname .= $trow[0].$trow[1]."、";
			}
		}
		$x++;
	}
	$showname = mb_substr($showname,0,-1);
}
$section->	addText("終點裁判\t：".$showname,$font14,$stafflistTab);
$sql = mysqli_query($splink,"Select STAFF from staffduty where keyid=\"10\"");
while ($row = mysqli_fetch_row($sql)){
	$temp = explode(",",$row[0]);
	$x = 0;
		$showname = "";
	while ($x < sizeof($temp)){
		$tsql = mysqli_query($splink,"Select CH_NAME,stafftitle from teacherinfo where STAFFCODE=\"".$temp[$x]."\"");
		while ($trow = mysqli_fetch_row($tsql)){
			if (in_array($temp[$x],$principal)) {
				$showname .= $trow[0]."校長、";
			} else if (in_array($temp[$x],$vineprincipal)){
				$showname .= $trow[0]."副校長、";
			} else if (in_array($temp[$x],$principalhelp)){
				$showname .= $trow[0]."助理副校長、"; 
			} else {
				$showname .= $trow[0].$trow[1]."、";
			}
		}
		$x++;
	}
	$showname = mb_substr($showname,0,-1);
}
$section->	addText("終點紀錄\t：".$showname,$font14,$stafflistTab);
$sql = mysqli_query($splink,"Select STAFF from staffduty where keyid=\"11\"");
while ($row = mysqli_fetch_row($sql)){
	$temp = explode(",",$row[0]);
	$x = 0;
		$showname = "";
	while ($x < sizeof($temp)){
		$tsql = mysqli_query($splink,"Select CH_NAME,stafftitle from teacherinfo where STAFFCODE=\"".$temp[$x]."\"");
		while ($trow = mysqli_fetch_row($tsql)){
			if (in_array($temp[$x],$principal)) {
				$showname .= $trow[0]."校長、";
			} else if (in_array($temp[$x],$vineprincipal)){
				$showname .= $trow[0]."副校長、";
			} else if (in_array($temp[$x],$principalhelp)){
				$showname .= $trow[0]."助理副校長、"; 
			} else {
				$showname .= $trow[0].$trow[1]."、";
			}
		}
		$x++;
	}
	$showname = mb_substr($showname,0,-1);
}
$sql = mysqli_query($splink,"Select STAFF from staffduty where keyid=\"12\"");
while ($row = mysqli_fetch_row($sql)){
	$temp = explode(",",$row[0]);
	$x = 0;
		$showname1 = "";
	while ($x < sizeof($temp)){
		$tsql = mysqli_query($splink,"Select CH_NAME,stafftitle from teacherinfo where STAFFCODE=\"".$temp[$x]."\"");
		while ($trow = mysqli_fetch_row($tsql)){
			if (in_array($temp[$x],$principal)) {
				$showname1 .= $trow[0]."校長、";
			} else if (in_array($temp[$x],$vineprincipal)){
				$showname1 .= $trow[0]."副校長、";
			} else if (in_array($temp[$x],$principalhelp)){
				$showname1 .= $trow[0]."助理副校長、"; 
			} else {
				$showname1 .= $trow[0].$trow[1]."、";
			}
		}
		$x++;
	}
	$showname1 = mb_substr($showname1,0,-1);
}
$section->	addText("彎道裁判\t：（第一接棒區）".$showname."、（第二接棒區）".$showname1,$font14,$stafflistTab);
$sql = mysqli_query($splink,"Select STAFF from staffduty where keyid=\"13\"");
while ($row = mysqli_fetch_row($sql)){
	$temp = explode(",",$row[0]);
	$x = 0;
		$showname = "";
	while ($x < sizeof($temp)){
		$tsql = mysqli_query($splink,"Select CH_NAME,stafftitle from teacherinfo where STAFFCODE=\"".$temp[$x]."\"");
		while ($trow = mysqli_fetch_row($tsql)){
			if (in_array($temp[$x],$principal)) {
				$showname .= $trow[0]."校長、";
			} else if (in_array($temp[$x],$vineprincipal)){
				$showname .= $trow[0]."副校長、";
			} else if (in_array($temp[$x],$principalhelp)){
				$showname .= $trow[0]."助理副校長、"; 
			} else {
				$showname .= $trow[0].$trow[1]."、";
			}
		}
		$x++;
	}
	$showname = mb_substr($showname,0,-1);
}

$section->	addText("　\t　（第三接棒區）".$showname,$font14,$stafflistTab);
$section->	addTextBreak();

$section->	addText("田賽",$font16u,$stafflisthead);
$sql = mysqli_query($splink,"Select STAFF from staffduty where keyid=\"14\"");
while ($row = mysqli_fetch_row($sql)){
	$temp = explode(",",$row[0]);
	$x = 0;
		$showname = "";
	while ($x < sizeof($temp)){
		$tsql = mysqli_query($splink,"Select CH_NAME,stafftitle from teacherinfo where STAFFCODE=\"".$temp[$x]."\"");
		while ($trow = mysqli_fetch_row($tsql)){
			if (in_array($temp[$x],$principal)) {
				$showname .= $trow[0]."校長、";
			} else if (in_array($temp[$x],$vineprincipal)){
				$showname .= $trow[0]."副校長、";
			} else if (in_array($temp[$x],$principalhelp)){
				$showname .= $trow[0]."助理副校長、"; 
			} else {
				$showname .= $trow[0].$trow[1]."、";
			}
		}
		$x++;
	}
	$showname = mb_substr($showname,0,-1);
}
$section->	addText("裁判長\t：".$showname,$font14,$stafflistTab);
$sql = mysqli_query($splink,"Select STAFF from staffduty where keyid=\"15\"");
while ($row = mysqli_fetch_row($sql)){
	$temp = explode(",",$row[0]);
	$x = 0;
		$showname = "";
	while ($x < sizeof($temp)){
		$tsql = mysqli_query($splink,"Select CH_NAME,stafftitle from teacherinfo where STAFFCODE=\"".$temp[$x]."\"");
		while ($trow = mysqli_fetch_row($tsql)){
			if (in_array($temp[$x],$principal)) {
				$showname .= $trow[0]."校長、";
			} else if (in_array($temp[$x],$vineprincipal)){
				$showname .= $trow[0]."副校長、";
			} else if (in_array($temp[$x],$principalhelp)){
				$showname .= $trow[0]."助理副校長、"; 
			} else {
				$showname .= $trow[0].$trow[1]."、";
			}
		}
		$x++;
	}
	$showname = mb_substr($showname,0,-1);
}
$section->	addText("跳高\t：".$showname,$font14,$stafflistTab);
$sql = mysqli_query($splink,"Select STAFF from staffduty where keyid=\"16\"");
while ($row = mysqli_fetch_row($sql)){
	$temp = explode(",",$row[0]);
	$x = 0;
		$showname = "";
	while ($x < sizeof($temp)){
		$tsql = mysqli_query($splink,"Select CH_NAME,stafftitle from teacherinfo where STAFFCODE=\"".$temp[$x]."\"");
		while ($trow = mysqli_fetch_row($tsql)){
			if (in_array($temp[$x],$principal)) {
				$showname .= $trow[0]."校長、";
			} else if (in_array($temp[$x],$vineprincipal)){
				$showname .= $trow[0]."副校長、";
			} else if (in_array($temp[$x],$principalhelp)){
				$showname .= $trow[0]."助理副校長、"; 
			} else {
				$showname .= $trow[0].$trow[1]."、";
			}
		}
		$x++;
	}
	$showname = mb_substr($showname,0,-1);
}
$section->	addText("跳遠/三級跳遠\t：（Group A） ".$showname,$font14,$stafflistTab);
$sql = mysqli_query($splink,"Select STAFF from staffduty where keyid=\"42\"");
while ($row = mysqli_fetch_row($sql)){
	$temp = explode(",",$row[0]);
	$x = 0;
		$showname = "";
	while ($x < sizeof($temp)){
		$tsql = mysqli_query($splink,"Select CH_NAME,stafftitle from teacherinfo where STAFFCODE=\"".$temp[$x]."\"");
		while ($trow = mysqli_fetch_row($tsql)){
			if (in_array($temp[$x],$principal)) {
				$showname .= $trow[0]."校長、";
			} else if (in_array($temp[$x],$vineprincipal)){
				$showname .= $trow[0]."副校長、";
			} else if (in_array($temp[$x],$principalhelp)){
				$showname .= $trow[0]."助理副校長、"; 
			} else {
				$showname .= $trow[0].$trow[1]."、";
			}
		}
		$x++;
	}
	$showname = mb_substr($showname,0,-1);
}

$section->	addText("　\t：（Group B) ".$showname,$font14,$stafflistTab);
$sql = mysqli_query($splink,"Select STAFF from staffduty where keyid=\"17\"");
while ($row = mysqli_fetch_row($sql)){
	$temp = explode(",",$row[0]);
	$x = 0;
		$showname = "";
	while ($x < sizeof($temp)){
		$tsql = mysqli_query($splink,"Select CH_NAME,stafftitle from teacherinfo where STAFFCODE=\"".$temp[$x]."\"");
		while ($trow = mysqli_fetch_row($tsql)){
			if (in_array($temp[$x],$principal)) {
				$showname .= $trow[0]."校長、";
			} else if (in_array($temp[$x],$vineprincipal)){
				$showname .= $trow[0]."副校長、";
			} else if (in_array($temp[$x],$principalhelp)){
				$showname .= $trow[0]."助理副校長、"; 
			} else {
				$showname .= $trow[0].$trow[1]."、";
			}
		}
		$x++;
	}
	$showname = mb_substr($showname,0,-1);
}
$section->	addText("鉛球\t：".$showname,$font14,$stafflistTab);
$sql = mysqli_query($splink,"Select STAFF from staffduty where keyid=\"18\"");
while ($row = mysqli_fetch_row($sql)){
	$temp = explode(",",$row[0]);
	$x = 0;
		$showname = "";
	while ($x < sizeof($temp)){
		$tsql = mysqli_query($splink,"Select CH_NAME,stafftitle from teacherinfo where STAFFCODE=\"".$temp[$x]."\"");
		while ($trow = mysqli_fetch_row($tsql)){
			if (in_array($temp[$x],$principal)) {
				$showname .= $trow[0]."校長、";
			} else if (in_array($temp[$x],$vineprincipal)){
				$showname .= $trow[0]."副校長、";
			} else if (in_array($temp[$x],$principalhelp)){
				$showname .= $trow[0]."助理副校長、"; 
			} else {
				$showname .= $trow[0].$trow[1]."、";
			}
		}
		$x++;
	}
	$showname = mb_substr($showname,0,-1);
}
$section->	addText("鐵餅\t：".$showname,$font14,$stafflistTab);
$sql = mysqli_query($splink,"Select STAFF from staffduty where keyid=\"19\"");
while ($row = mysqli_fetch_row($sql)){
	$temp = explode(",",$row[0]);
	$x = 0;
		$showname = "";
	while ($x < sizeof($temp)){
		$tsql = mysqli_query($splink,"Select CH_NAME,stafftitle from teacherinfo where STAFFCODE=\"".$temp[$x]."\"");
		while ($trow = mysqli_fetch_row($tsql)){
			if (in_array($temp[$x],$principal)) {
				$showname .= $trow[0]."校長、";
			} else if (in_array($temp[$x],$vineprincipal)){
				$showname .= $trow[0]."副校長、";
			} else if (in_array($temp[$x],$principalhelp)){
				$showname .= $trow[0]."助理副校長、"; 
			} else {
				$showname .= $trow[0].$trow[1]."、";
			}
		}
		$x++;
	}
	$showname = mb_substr($showname,0,-1);
}
$section->	addText("標槍\t：".$showname,$font14,$stafflistTab);

$section-> addPageBreak();
$section->	addText("司令台",$font16u,$stafflisthead);
$sql = mysqli_query($splink,"Select STAFF from staffduty where keyid=\"20\"");
while ($row = mysqli_fetch_row($sql)){
	$temp = explode(",",$row[0]);
	$x = 0;
		$showname = "";
	while ($x < sizeof($temp)){
		$tsql = mysqli_query($splink,"Select CH_NAME,stafftitle from teacherinfo where STAFFCODE=\"".$temp[$x]."\"");
		while ($trow = mysqli_fetch_row($tsql)){
			if (in_array($temp[$x],$principal)) {
				$showname .= $trow[0]."校長、";
			} else if (in_array($temp[$x],$vineprincipal)){
				$showname .= $trow[0]."副校長、";
			} else if (in_array($temp[$x],$principalhelp)){
				$showname .= $trow[0]."助理副校長、"; 
			} else {
				$showname .= $trow[0].$trow[1]."、";
			}
		}
		$x++;
	}
	$showname = mb_substr($showname,0,-1);
}
$section->	addText("宣佈\t：".$showname,$font14,$stafflistTab);

$sql = mysqli_query($splink,"Select STAFF from staffduty where keyid=\"21\"");
while ($row = mysqli_fetch_row($sql)){
	$temp = explode(",",$row[0]);
	$x = 0;
		$showname = "";
	while ($x < sizeof($temp)){
		$tsql = mysqli_query($splink,"Select CH_NAME,stafftitle from teacherinfo where STAFFCODE=\"".$temp[$x]."\"");
		while ($trow = mysqli_fetch_row($tsql)){
			if (in_array($temp[$x],$principal)) {
				$showname .= $trow[0]."校長、";
			} else if (in_array($temp[$x],$vineprincipal)){
				$showname .= $trow[0]."副校長、";
			} else if (in_array($temp[$x],$principalhelp)){
				$showname .= $trow[0]."助理副校長、"; 
			} else {
				$showname .= $trow[0].$trow[1]."、";
			}
		}
		$x++;
	}
	$showname = mb_substr($showname,0,-1);
}
$section->	addText("資訊科技\t：".$showname,$font14,$stafflistTab);

$sql = mysqli_query($splink,"Select STAFF from staffduty where keyid=\"22\"");
while ($row = mysqli_fetch_row($sql)){
	$temp = explode(",",$row[0]);
	$x = 0;
		$showname = "";
	while ($x < sizeof($temp)){
		$tsql = mysqli_query($splink,"Select CH_NAME,stafftitle from teacherinfo where STAFFCODE=\"".$temp[$x]."\"");
		while ($trow = mysqli_fetch_row($tsql)){
			if (in_array($temp[$x],$principal)) {
				$showname .= $trow[0]."校長、";
			} else if (in_array($temp[$x],$vineprincipal)){
				$showname .= $trow[0]."副校長、";
			} else if (in_array($temp[$x],$principalhelp)){
				$showname .= $trow[0]."助理副校長、"; 
			} else {
				$showname .= $trow[0].$trow[1]."、";
			}
		}
		$x++;
	}
	$showname = mb_substr($showname,0,-1);
}
$section->	addText("司令台紀錄\t：".$showname,$font14,$stafflistTab);

$sql = mysqli_query($splink,"Select STAFF from staffduty where keyid=\"23\"");
while ($row = mysqli_fetch_row($sql)){
	$temp = explode(",",$row[0]);
	$x = 0;
		$showname = "";
	while ($x < sizeof($temp)){
		$tsql = mysqli_query($splink,"Select CH_NAME,stafftitle from teacherinfo where STAFFCODE=\"".$temp[$x]."\"");
		while ($trow = mysqli_fetch_row($tsql)){
			if (in_array($temp[$x],$principal)) {
				$showname .= $trow[0]."校長、";
			} else if (in_array($temp[$x],$vineprincipal)){
				$showname .= $trow[0]."副校長、";
			} else if (in_array($temp[$x],$principalhelp)){
				$showname .= $trow[0]."助理副校長、"; 
			} else {
				$showname .= $trow[0].$trow[1]."、";
			}
		}
		$x++;
	}
	$showname = mb_substr($showname,0,-1);
}
$section->	addText("獎品\t：".$showname,$font14,$stafflistTab);

$sql = mysqli_query($splink,"Select STAFF from staffduty where keyid=\"24\"");
while ($row = mysqli_fetch_row($sql)){
	$temp = explode(",",$row[0]);
	$x = 0;
		$showname = "";
	while ($x < sizeof($temp)){
		$tsql = mysqli_query($splink,"Select CH_NAME,stafftitle from teacherinfo where STAFFCODE=\"".$temp[$x]."\"");
		while ($trow = mysqli_fetch_row($tsql)){
			if (in_array($temp[$x],$principal)) {
				$showname .= $trow[0]."校長、";
			} else if (in_array($temp[$x],$vineprincipal)){
				$showname .= $trow[0]."副校長、";
			} else if (in_array($temp[$x],$principalhelp)){
				$showname .= $trow[0]."助理副校長、"; 
			} else {
				$showname .= $trow[0].$trow[1]."、";
			}
		}
		$x++;
	}
	$showname = mb_substr($showname,0,-1);
}
$section->	addText("器材及音響\t：".$showname.$showname,$font14,$stafflistTab);

$sql = mysqli_query($splink,"Select STAFF from staffduty where keyid=\"25\"");
while ($row = mysqli_fetch_row($sql)){
	$temp = explode(",",$row[0]);
	$x = 0;
		$showname = "";
	while ($x < sizeof($temp)){
		$tsql = mysqli_query($splink,"Select CH_NAME,stafftitle from teacherinfo where STAFFCODE=\"".$temp[$x]."\"");
		while ($trow = mysqli_fetch_row($tsql)){
			if (in_array($temp[$x],$principal)) {
				$showname .= $trow[0]."校長、";
			} else if (in_array($temp[$x],$vineprincipal)){
				$showname .= $trow[0]."副校長、";
			} else if (in_array($temp[$x],$principalhelp)){
				$showname .= $trow[0]."助理副校長、"; 
			} else {
				$showname .= $trow[0].$trow[1]."、";
			}
		}
		$x++;
	}
	$showname = mb_substr($showname,0,-1);
}
$section->	addText("學生會\t：".$showname,$font14,$stafflistTab);

$sql = mysqli_query($splink,"Select STAFF from staffduty where keyid=\"26\"");
while ($row = mysqli_fetch_row($sql)){
	$temp = explode(",",$row[0]);
	$x = 0;
		$showname = "";
	while ($x < sizeof($temp)){
		$tsql = mysqli_query($splink,"Select CH_NAME,stafftitle from teacherinfo where STAFFCODE=\"".$temp[$x]."\"");
		while ($trow = mysqli_fetch_row($tsql)){
			if (in_array($temp[$x],$principal)) {
				$showname .= $trow[0]."校長、";
			} else if (in_array($temp[$x],$vineprincipal)){
				$showname .= $trow[0]."副校長、";
			} else if (in_array($temp[$x],$principalhelp)){
				$showname .= $trow[0]."助理副校長、"; 
			} else {
				$showname .= $trow[0].$trow[1]."、";
			}
		}
		$x++;
	}
	$showname = mb_substr($showname,0,-1);
}
$section->	addText("安全\t：".$showname,$font14,$stafflistTab);

$sql = mysqli_query($splink,"Select STAFF from staffduty where keyid=\"27\"");
while ($row = mysqli_fetch_row($sql)){
	$temp = explode(",",$row[0]);
	$x = 0;
		$showname = "";
	while ($x < sizeof($temp)){
		$tsql = mysqli_query($splink,"Select CH_NAME,stafftitle from teacherinfo where STAFFCODE=\"".$temp[$x]."\"");
		while ($trow = mysqli_fetch_row($tsql)){
			if (in_array($temp[$x],$principal)) {
				$showname .= $trow[0]."校長、";
			} else if (in_array($temp[$x],$vineprincipal)){
				$showname .= $trow[0]."副校長、";
			} else if (in_array($temp[$x],$principalhelp)){
				$showname .= $trow[0]."助理副校長、"; 
			} else {
				$showname .= $trow[0].$trow[1]."、";
			}
		}
		$x++;
	}
	$showname = mb_substr($showname,0,-1);
}
$section->	addText("救護\t：".$showname,$font14,$stafflistTab);

$sql = mysqli_query($splink,"Select STAFF from staffduty where keyid=\"28\"");
while ($row = mysqli_fetch_row($sql)){
	$temp = explode(",",$row[0]);
	$x = 0;
		$showname = "";
	while ($x < sizeof($temp)){
		$tsql = mysqli_query($splink,"Select CH_NAME,stafftitle from teacherinfo where STAFFCODE=\"".$temp[$x]."\"");
		while ($trow = mysqli_fetch_row($tsql)){
			if (in_array($temp[$x],$principal)) {
				$showname .= $trow[0]."校長、";
			} else if (in_array($temp[$x],$vineprincipal)){
				$showname .= $trow[0]."副校長、";
			} else if (in_array($temp[$x],$principalhelp)){
				$showname .= $trow[0]."助理副校長、"; 
			} else {
				$showname .= $trow[0].$trow[1]."、";
			}
		}
		$x++;
	}
	$showname = mb_substr($showname,0,-1);
}
$section->	addText("上訢委員會\t：".$showname,$font14,$stafflistTab);

$section->	addTextBreak();
$section->	addText("看台及紀律",$font16u,$stafflisthead);
$sql = mysqli_query($splink,"Select STAFF from staffduty where keyid=\"29\"");
while ($row = mysqli_fetch_row($sql)){
	$temp = explode(",",$row[0]);
	$x = 0;
		$showname = "";
	while ($x < sizeof($temp)){
		$tsql = mysqli_query($splink,"Select CH_NAME,stafftitle from teacherinfo where STAFFCODE=\"".$temp[$x]."\"");
		while ($trow = mysqli_fetch_row($tsql)){
			if (in_array($temp[$x],$principal)) {
				$showname .= $trow[0]."校長、";
			} else if (in_array($temp[$x],$vineprincipal)){
				$showname .= $trow[0]."副校長、";
			} else if (in_array($temp[$x],$principalhelp)){
				$showname .= $trow[0]."助理副校長、"; 
			} else {
				$showname .= $trow[0].$trow[1]."、";
			}
		}
		$x++;
	}
	$showname = mb_substr($showname,0,-1);
}
$section->	addText("博社\t：".$showname,$font14,$stafflistTab);

$sql = mysqli_query($splink,"Select STAFF from staffduty where keyid=\"30\"");
while ($row = mysqli_fetch_row($sql)){
	$temp = explode(",",$row[0]);
	$x = 0;
		$showname = "";
	while ($x < sizeof($temp)){
		$tsql = mysqli_query($splink,"Select CH_NAME,stafftitle from teacherinfo where STAFFCODE=\"".$temp[$x]."\"");
		while ($trow = mysqli_fetch_row($tsql)){
			if (in_array($temp[$x],$principal)) {
				$showname .= $trow[0]."校長、";
			} else if (in_array($temp[$x],$vineprincipal)){
				$showname .= $trow[0]."副校長、";
			} else if (in_array($temp[$x],$principalhelp)){
				$showname .= $trow[0]."助理副校長、"; 
			} else {
				$showname .= $trow[0].$trow[1]."、";
			}
		}
		$x++;
	}
	$showname = mb_substr($showname,0,-1);
}
$section->	addText("文社\t：".$showname,$font14,$stafflistTab);

$sql = mysqli_query($splink,"Select STAFF from staffduty where keyid=\"31\"");
while ($row = mysqli_fetch_row($sql)){
	$temp = explode(",",$row[0]);
	$x = 0;
		$showname = "";
	while ($x < sizeof($temp)){
		$tsql = mysqli_query($splink,"Select CH_NAME,stafftitle from teacherinfo where STAFFCODE=\"".$temp[$x]."\"");
		while ($trow = mysqli_fetch_row($tsql)){
			if (in_array($temp[$x],$principal)) {
				$showname .= $trow[0]."校長、";
			} else if (in_array($temp[$x],$vineprincipal)){
				$showname .= $trow[0]."副校長、";
			} else if (in_array($temp[$x],$principalhelp)){
				$showname .= $trow[0]."助理副校長、"; 
			} else {
				$showname .= $trow[0].$trow[1]."、";
			}
		}
		$x++;
	}
	$showname = mb_substr($showname,0,-1);
}
$section->	addText("愛社\t：".$showname,$font14,$stafflistTab);

$sql = mysqli_query($splink,"Select STAFF from staffduty where keyid=\"32\"");
while ($row = mysqli_fetch_row($sql)){
	$temp = explode(",",$row[0]);
	$x = 0;
		$showname = "";
	while ($x < sizeof($temp)){
		$tsql = mysqli_query($splink,"Select CH_NAME,stafftitle from teacherinfo where STAFFCODE=\"".$temp[$x]."\"");
		while ($trow = mysqli_fetch_row($tsql)){
			if (in_array($temp[$x],$principal)) {
				$showname .= $trow[0]."校長、";
			} else if (in_array($temp[$x],$vineprincipal)){
				$showname .= $trow[0]."副校長、";
			} else if (in_array($temp[$x],$principalhelp)){
				$showname .= $trow[0]."助理副校長、"; 
			} else {
				$showname .= $trow[0].$trow[1]."、";
			}
		}
		$x++;
	}
	$showname = mb_substr($showname,0,-1);
}
$section->	addText("德社\t：".$showname,$font14,$stafflistTab);

$sql = mysqli_query($splink,"Select STAFF from staffduty where keyid=\"33\"");
while ($row = mysqli_fetch_row($sql)){
	$temp = explode(",",$row[0]);
	$x = 0;
		$showname = "";
	while ($x < sizeof($temp)){
		$tsql = mysqli_query($splink,"Select CH_NAME,stafftitle from teacherinfo where STAFFCODE=\"".$temp[$x]."\"");
		while ($trow = mysqli_fetch_row($tsql)){
			if (in_array($temp[$x],$principal)) {
				$showname .= $trow[0]."校長、";
			} else if (in_array($temp[$x],$vineprincipal)){
				$showname .= $trow[0]."副校長、";
			} else if (in_array($temp[$x],$principalhelp)){
				$showname .= $trow[0]."助理副校長、"; 
			} else {
				$showname .= $trow[0].$trow[1]."、";
			}
		}
		$x++;
	}
	$showname = mb_substr($showname,0,-1);
}
$section->	addText("紀律\t：".$showname,$font14,$stafflistTab);

$section->	addTextBreak();
$section->	addText("典禮",$font16u,$stafflisthead);

$sql = mysqli_query($splink,"Select STAFF from staffduty where keyid=\"34\"");
while ($row = mysqli_fetch_row($sql)){
	$temp = explode(",",$row[0]);
	$x = 0;
		$showname = "";
	while ($x < sizeof($temp)){
		$tsql = mysqli_query($splink,"Select CH_NAME,stafftitle from teacherinfo where STAFFCODE=\"".$temp[$x]."\"");
		while ($trow = mysqli_fetch_row($tsql)){
			if (in_array($temp[$x],$principal)) {
				$showname .= $trow[0]."校長、";
			} else if (in_array($temp[$x],$vineprincipal)){
				$showname .= $trow[0]."副校長、";
			} else if (in_array($temp[$x],$principalhelp)){
				$showname .= $trow[0]."助理副校長、"; 
			} else {
				$showname .= $trow[0].$trow[1]."、";
			}
		}
		$x++;
	}
	$showname = mb_substr($showname,0,-1);
}
$section->	addText("司儀\t：".$showname,$font14,$stafflistTab);
$section->	addText("　\t　 XXX同學",$font14,$stafflistTab);

$sql = mysqli_query($splink,"Select STAFF from staffduty where keyid=\"35\"");
while ($row = mysqli_fetch_row($sql)){
	$temp = explode(",",$row[0]);
	$x = 0;
		$showname = "";
	while ($x < sizeof($temp)){
		$tsql = mysqli_query($splink,"Select CH_NAME,stafftitle from teacherinfo where STAFFCODE=\"".$temp[$x]."\"");
		while ($trow = mysqli_fetch_row($tsql)){
			if (in_array($temp[$x],$principal)) {
				$showname .= $trow[0]."校長、";
			} else if (in_array($temp[$x],$vineprincipal)){
				$showname .= $trow[0]."副校長、";
			} else if (in_array($temp[$x],$principalhelp)){
				$showname .= $trow[0]."助理副校長、"; 
			} else {
				$showname .= $trow[0].$trow[1]."、";
			}
		}
		$x++;
	}
	$showname = mb_substr($showname,0,-1);
}
$section->	addText("接待\t：".$showname,$font14,$stafflistTab);

$sql = mysqli_query($splink,"Select STAFF from staffduty where keyid=\"36\"");
while ($row = mysqli_fetch_row($sql)){
	$temp = explode(",",$row[0]);
	$x = 0;
		$showname = "";
	while ($x < sizeof($temp)){
		$tsql = mysqli_query($splink,"Select CH_NAME,stafftitle from teacherinfo where STAFFCODE=\"".$temp[$x]."\"");
		while ($trow = mysqli_fetch_row($tsql)){
			if (in_array($temp[$x],$principal)) {
				$showname .= $trow[0]."校長、";
			} else if (in_array($temp[$x],$vineprincipal)){
				$showname .= $trow[0]."副校長、";
			} else if (in_array($temp[$x],$principalhelp)){
				$showname .= $trow[0]."助理副校長、"; 
			} else {
				$showname .= $trow[0].$trow[1]."、";
			}
		}
		$x++;
	}
	$showname = mb_substr($showname,0,-1);
}
$section->	addText("茶點\t：".$showname,$font14,$stafflistTab);

$sql = mysqli_query($splink,"Select STAFF from staffduty where keyid=\"37\"");
while ($row = mysqli_fetch_row($sql)){
	$temp = explode(",",$row[0]);
	$x = 0;
		$showname = "";
	while ($x < sizeof($temp)){
		$tsql = mysqli_query($splink,"Select CH_NAME,stafftitle from teacherinfo where STAFFCODE=\"".$temp[$x]."\"");
		while ($trow = mysqli_fetch_row($tsql)){
			if (in_array($temp[$x],$principal)) {
				$showname .= $trow[0]."校長、";
			} else if (in_array($temp[$x],$vineprincipal)){
				$showname .= $trow[0]."副校長、";
			} else if (in_array($temp[$x],$principalhelp)){
				$showname .= $trow[0]."助理副校長、"; 
			} else {
				$showname .= $trow[0].$trow[1]."、";
			}
		}
		$x++;
	}
	$showname = mb_substr($showname,0,-1);
}
$section->	addText("佈置\t：".$showname,$font14,$stafflistTab);

$sql = mysqli_query($splink,"Select STAFF from staffduty where keyid=\"38\"");
while ($row = mysqli_fetch_row($sql)){
	$temp = explode(",",$row[0]);
	$x = 0;
		$showname = "";
	while ($x < sizeof($temp)){
		$tsql = mysqli_query($splink,"Select CH_NAME,stafftitle from teacherinfo where STAFFCODE=\"".$temp[$x]."\"");
		while ($trow = mysqli_fetch_row($tsql)){
			if (in_array($temp[$x],$principal)) {
				$showname .= $trow[0]."校長、";
			} else if (in_array($temp[$x],$vineprincipal)){
				$showname .= $trow[0]."副校長、";
			} else if (in_array($temp[$x],$principalhelp)){
				$showname .= $trow[0]."助理副校長、"; 
			} else {
				$showname .= $trow[0].$trow[1]."、";
			}
		}
		$x++;
	}
	$showname = mb_substr($showname,0,-1);
}
$section->	addText("攝錄\t：".$showname,$font14,$stafflistTab);

$sql = mysqli_query($splink,"Select STAFF from staffduty where keyid=\"39\"");
while ($row = mysqli_fetch_row($sql)){
	$temp = explode(",",$row[0]);
	$x = 0;
		$showname = "";
	while ($x < sizeof($temp)){
		$tsql = mysqli_query($splink,"Select CH_NAME,stafftitle from teacherinfo where STAFFCODE=\"".$temp[$x]."\"");
		while ($trow = mysqli_fetch_row($tsql)){
			if (in_array($temp[$x],$principal)) {
				$showname .= $trow[0]."校長、";
			} else if (in_array($temp[$x],$vineprincipal)){
				$showname .= $trow[0]."副校長、";
			} else if (in_array($temp[$x],$principalhelp)){
				$showname .= $trow[0]."助理副校長、"; 
			} else {
				$showname .= $trow[0].$trow[1]."、";
			}
		}
		$x++;
	}
	$showname = mb_substr($showname,0,-1);
}
$section->	addText("升旗及降旗\t：童軍、".$showname,$font14,$stafflistTab);

$sql = mysqli_query($splink,"Select STAFF from staffduty where keyid=\"40\"");
while ($row = mysqli_fetch_row($sql)){
	$temp = explode(",",$row[0]);
	$x = 0;
		$showname = "";
	while ($x < sizeof($temp)){
		$tsql = mysqli_query($splink,"Select CH_NAME,stafftitle from teacherinfo where STAFFCODE=\"".$temp[$x]."\"");
		while ($trow = mysqli_fetch_row($tsql)){
			if (in_array($temp[$x],$principal)) {
				$showname .= $trow[0]."校長、";
			} else if (in_array($temp[$x],$vineprincipal)){
				$showname .= $trow[0]."副校長、";
			} else if (in_array($temp[$x],$principalhelp)){
				$showname .= $trow[0]."助理副校長、"; 
			} else {
				$showname .= $trow[0].$trow[1]."、";
			}
		}
		$x++;
	}
	$showname = mb_substr($showname,0,-1);
}
$section->	addText("進場\t：".$showname,$font14,$stafflistTab);

$sql = mysqli_query($splink,"Select STAFF from staffduty where keyid=\"41\"");
while ($row = mysqli_fetch_row($sql)){
	$temp = explode(",",$row[0]);
	$x = 0;
		$showname = "";
	while ($x < sizeof($temp)){
		$tsql = mysqli_query($splink,"Select CH_NAME,stafftitle from teacherinfo where STAFFCODE=\"".$temp[$x]."\"");
		while ($trow = mysqli_fetch_row($tsql)){
			if (in_array($temp[$x],$principal)) {
				$showname .= $trow[0]."校長、";
			} else if (in_array($temp[$x],$vineprincipal)){
				$showname .= $trow[0]."副校長、";
			} else if (in_array($temp[$x],$principalhelp)){
				$showname .= $trow[0]."助理副校長、"; 
			} else {
				$showname .= $trow[0].$trow[1]."、";
			}
		}
		$x++;
	}
	$showname = mb_substr($showname,0,-1);
}
$section->	addText("步操樂團\t：".$showname,$font14,$stafflistTab);

$section->	addPageBreak();

//統計數字
$section-> addText($company,$bold18,$paracenter);
$section-> addText($sportdayname,$bold18,$paracenter);
$section->	addText('學社報名參加人數統計',$font16u,$parastatistsheader);
$tablestudcount = $section ->	addTable($contentTableStyle);
//title
$tablestudcount -> addRow(300);
$tablestudcount ->	addCell(1000, array('vMerge'=>'restart', 'valign'=>'center','borderColor' => '000000','borderTopSize'=>20,'borderLeftSize'=>20,'borderRightSize'=>10))
				->	addText("學社",$statistfontb,$paracenter);
$tablestudcount ->	addCell(1200, array('vMerge'=>'restart', 'valign'=>'center','borderColor' => '000000','borderTopSize'=>20,'borderLeftSize'=>10,'borderRightSize'=>20))
				->	addText("學社名稱",$statistfontb,$paracenter);
$tablestudcount ->	addCell(2200, array('gridSpan'=>3, 'valign'=>'center','borderColor' => '000000','borderTopSize'=>20,'borderLeftSize'=>20,'borderRightSize'=>20,'borderBottomSize'=>10))
				->	addText("甲組",$statistfontb,$paracenter);
$tablestudcount ->	addCell(2200, array('gridSpan'=>3, 'valign'=>'center','borderColor' => '000000','borderTopSize'=>20,'borderLeftSize'=>20,'borderRightSize'=>20,'borderBottomSize'=>10))
				->	addText("乙組",$statistfontb,$paracenter);
$tablestudcount ->	addCell(2200, array('gridSpan'=>3, 'valign'=>'center','borderColor' => '000000','borderTopSize'=>20,'borderLeftSize'=>20,'borderRightSize'=>20,'borderBottomSize'=>10))
				->	addText("丙組",$statistfontb,$paracenter);
$tablestudcount ->	addCell(1200, array('vMerge'=>'restart', 'valign'=>'center','borderColor' => '000000','borderTopSize'=>20,'borderLeftSize'=>20,'borderRightSize'=>20))
				->	addText("總數",$statistfontb,$paracenter);
$tablestudcount ->	addRow(300);
$tablestudcount -> addCell(null, array('vMerge' => 'continue', 'valign'=>'center','borderColor' => '000000','borderBottomSize'=>20,'borderLeftSize'=>20,'borderRightSize'=>10));
$tablestudcount -> addCell(null, array('vMerge' => 'continue', 'valign'=>'center','borderColor' => '000000','borderBottomSize'=>20,'borderLeftSize'=>10,'borderRightSize'=>20));
$tablestudcount ->	addCell(700, array( 'valign'=>'center','borderColor' => '000000','borderBottomSize'=>20,'borderLeftSize'=>20,'borderRightSize'=>10))
				->	addText("男",$statistfontb,$paracenter);
$tablestudcount ->	addCell(700, array( 'valign'=>'center','borderColor' => '000000','borderBottomSize'=>20,'borderLeftSize'=>10,'borderRightSize'=>10))
				->	addText("女",$statistfontb,$paracenter);
$tablestudcount ->	addCell(800, array( 'valign'=>'center','borderColor' => '000000','borderBottomSize'=>20,'borderLeftSize'=>10,'borderRightSize'=>20))
				->	addText("總數",$statistfontb,$paracenter);
$tablestudcount ->	addCell(700, array( 'valign'=>'center','borderColor' => '000000','borderBottomSize'=>20,'borderLeftSize'=>20,'borderRightSize'=>10))
				->	addText("男",$statistfontb,$paracenter);
$tablestudcount ->	addCell(700, array( 'valign'=>'center','borderColor' => '000000','borderBottomSize'=>20,'borderLeftSize'=>10,'borderRightSize'=>10))
				->	addText("女",$statistfontb,$paracenter);
$tablestudcount ->	addCell(800, array( 'valign'=>'center','borderColor' => '000000','borderBottomSize'=>20,'borderLeftSize'=>10,'borderRightSize'=>20))
				->	addText("總數",$statistfontb,$paracenter);
$tablestudcount ->	addCell(700, array( 'valign'=>'center','borderColor' => '000000','borderBottomSize'=>20,'borderLeftSize'=>20,'borderRightSize'=>10))
				->	addText("男",$statistfontb,$paracenter);
$tablestudcount ->	addCell(700, array( 'valign'=>'center','borderColor' => '000000','borderBottomSize'=>20,'borderLeftSize'=>10,'borderRightSize'=>10))
				->	addText("女",$statistfontb,$paracenter);
$tablestudcount ->	addCell(800, array( 'valign'=>'center','borderColor' => '000000','borderBottomSize'=>20,'borderLeftSize'=>10,'borderRightSize'=>20))
				->	addText("總數",$statistfontb,$paracenter);
$tablestudcount -> addCell(null, array('vMerge' => 'continue', 'valign'=>'center','borderColor' => '000000','borderBottomSize'=>20,'borderLeftSize'=>20,'borderRightSize'=>20));
//content
$amt = 0; //Grade A total boy
$aft = 0; //Grade A total girl
$bmt = 0; //Grade B total boy
$bft = 0; //Grade B total girl
$cmt = 0; //Grade C total boy
$cft = 0; //Grade C total girl
$sql = mysqli_query($splink,"Select SCHHOUSE from studentinfo GROUP by SCHHOUSE");
while ($row = mysqli_fetch_row($sql)){
	$tablestudcount ->	addRow(300);  //開新行
	if ($row[0] == "R") {
		$hsename = $txthouseRed;
	} else if ($row[0] == "Y") {
		$hsename = $txthouseYellow;
	} else if ($row[0] == "B") {
		$hsename = $txthouseBlue;
	} else {
		$hsename = $txthouseGreen;
	}
	$tablestudcount ->	addCell(1000,$borderbot10lef20)	->	addText($row[0],$statistfontb,$paracenter);
	$tablestudcount ->	addCell(1200, $borderbot10lef10)->	addText($hsename,$statistfontb,$paracenter);
	$hmt = 0;
	$hft = 0;
	$csql = mysqli_query($splink,"Select A.STUID from APPLICATION_COMPETITION AS A inner JOIN studentinfo AS B on A.STUID=B.STUID where B.SCHHOUSE=\"".$row[0]."\" AND SEX=\"M\" AND LEFT(B.DOB,4 ) < \"".$gradeByr."\" GROUP BY A.STUID");
	$hmt = mysqli_num_rows($csql);
	$amt = $amt + $hmt;
	$tablestudcount ->	addCell(700, $borderbot10lef20) ->	addText($hmt,$statistfont, $paracenter);
	$csql = mysqli_query($splink,"Select A.STUID from APPLICATION_COMPETITION AS A inner JOIN studentinfo AS B on A.STUID=B.STUID where B.SCHHOUSE=\"".$row[0]."\" AND SEX=\"F\" AND LEFT(B.DOB,4 ) < \"".$gradeByr."\" GROUP BY A.STUID");
	$hft = mysqli_num_rows($csql);
	$aft = $aft + $hft;
	$tablestudcount ->	addCell(700, $borderbot10lef10) ->	addText($hft,$statistfont, $paracenter);
	$tablestudcount ->	addCell(800, $borderbot10lef10) ->	addText($hmt + $hft,$statistfontb, $paracenter);
	$hmt = 0;
	$hft = 0;
	$csql = mysqli_query($splink,"Select A.STUID from APPLICATION_COMPETITION AS A inner JOIN studentinfo AS B on A.STUID=B.STUID where B.SCHHOUSE=\"".$row[0]."\" AND SEX=\"M\" AND LEFT(B.DOB,4 ) >= \"".$gradeByr."\" AND LEFT(B.DOB,4 ) < \"".$gradeCyr."\"  GROUP BY A.STUID");
	$hmt = mysqli_num_rows($csql);
	$bmt = $bmt + $hmt;
	$tablestudcount ->	addCell(700, $borderbot10lef20) ->	addText($hmt,$statistfont, $paracenter);
	$csql = mysqli_query($splink,"Select A.STUID from APPLICATION_COMPETITION AS A inner JOIN studentinfo AS B on A.STUID=B.STUID where B.SCHHOUSE=\"".$row[0]."\" AND SEX=\"F\" AND LEFT(B.DOB,4 ) >= \"".$gradeByr."\" AND LEFT(B.DOB,4 ) <= \"".$gradeCyr."\" GROUP BY A.STUID");
	$hft = mysqli_num_rows($csql);
	$bft = $bft + $hft;
	$tablestudcount ->	addCell(700, $borderbot10lef10) ->	addText($bft,$statistfont, $paracenter);
	$tablestudcount ->	addCell(800, $borderbot10lef10) ->	addText($hmt + $hft,$statistfontb, $paracenter);
	$hmt = 0;
	$hft = 0;
	$csql = mysqli_query($splink,"Select A.STUID from APPLICATION_COMPETITION AS A inner JOIN studentinfo AS B on A.STUID=B.STUID where B.SCHHOUSE=\"".$row[0]."\" AND SEX=\"M\" AND LEFT(B.DOB,4 ) >= \"".$gradeCyr."\" GROUP BY A.STUID");
	$hmt = mysqli_num_rows($csql);
	$cmt = $cmt + $hmt;
	$tablestudcount ->	addCell(700, $borderbot10lef20) ->	addText($hmt,$statistfont, $paracenter);
	$csql = mysqli_query($splink,"Select A.STUID from APPLICATION_COMPETITION AS A inner JOIN studentinfo AS B on A.STUID=B.STUID where B.SCHHOUSE=\"".$row[0]."\" AND SEX=\"F\" AND LEFT(B.DOB,4 ) >= \"".$gradeCyr."\" GROUP BY A.STUID");
	$hft = mysqli_num_rows($csql);
	$cft = $cft + $hft;
	$tablestudcount ->	addCell(700, $borderbot10lef10) ->	addText($hft,$statistfont, $paracenter);
	$tablestudcount ->	addCell(800, $borderbot10lef10) ->	addText($hmt + $hft,$statistfontb, $paracenter);
	$tablestudcount ->	addCell(1200, $borderbot20lef20rig20) ->	addText($hmt+$hft+$hmt+$hft+$hmt + $hft,$statistfontb, $paracenter);

}
$tablestudcount ->	addRow(300);  //開新行
$tablestudcount ->	addCell(1000, array('borderColor' => '000000','borderTopSize'=>20));
$tablestudcount ->	addCell(1200, array('borderColor' => '000000','borderTopSize'=>20));
$tablestudcount ->	addCell(700, $bordertop20bot20lef20) ->	addText($amt,$statistfont,$paracenter);
$tablestudcount ->	addCell(700, $bordertop20bot20lef10) ->	addText($aft,$statistfont,$paracenter);
$tablestudcount ->	addCell(800, $bordertop20bot20lef10) ->	addText($amt+$aft,$statistfontb,$paracenter);
$tablestudcount ->	addCell(700, $bordertop20bot20lef20) ->	addText($bmt,$statistfont,$paracenter);
$tablestudcount ->	addCell(700, $bordertop20bot20lef10) ->	addText($bft,$statistfont,$paracenter);
$tablestudcount ->	addCell(800, $bordertop20bot20lef10) ->	addText($bmt+$bft,$statistfontb,$paracenter);
$tablestudcount ->	addCell(700, $bordertop20bot20lef20) ->	addText($cmt,$statistfont,$paracenter);
$tablestudcount ->	addCell(700, $bordertop20bot20lef10) ->	addText($cft,$statistfont,$paracenter);
$tablestudcount ->	addCell(800, $bordertop20bot20lef10) ->	addText($cmt+$cft,$statistfontb,$paracenter);
$tablestudcount ->	addCell(1200, $borderall20) ->	addText($amt+$aft+$bmt+$bft+$cmt+$cft,$statistfontb,$paracenter);

$section->	addText('學社報名參加人次統計',$font16u,$parastatistsheader);
$tableheadcount = $section ->	addTable($contentTableStyle);
//title
$tableheadcount -> addRow(300);
$tableheadcount ->	addCell(1000, array('vMerge'=>'restart', 'valign'=>'center','borderColor' => '000000','borderTopSize'=>20,'borderLeftSize'=>20,'borderRightSize'=>10))
				->	addText("學社",$statistfontb,$paracenter);
$tableheadcount ->	addCell(1200, array('vMerge'=>'restart', 'valign'=>'center','borderColor' => '000000','borderTopSize'=>20,'borderLeftSize'=>10,'borderRightSize'=>20))
				->	addText("學社名稱",$statistfontb,$paracenter);
$tableheadcount ->	addCell(2200, array('gridSpan'=>3, 'valign'=>'center','borderColor' => '000000','borderTopSize'=>20,'borderLeftSize'=>20,'borderRightSize'=>20,'borderBottomSize'=>10))
				->	addText("甲組",$statistfontb,$paracenter);
$tableheadcount ->	addCell(2200, array('gridSpan'=>3, 'valign'=>'center','borderColor' => '000000','borderTopSize'=>20,'borderLeftSize'=>20,'borderRightSize'=>20,'borderBottomSize'=>10))
				->	addText("乙組",$statistfontb,$paracenter);
$tableheadcount ->	addCell(2200, array('gridSpan'=>3, 'valign'=>'center','borderColor' => '000000','borderTopSize'=>20,'borderLeftSize'=>20,'borderRightSize'=>20,'borderBottomSize'=>10))
				->	addText("丙組",$statistfontb,$paracenter);
$tableheadcount ->	addCell(1200, array('vMerge'=>'restart', 'valign'=>'center','borderColor' => '000000','borderTopSize'=>20,'borderLeftSize'=>20,'borderRightSize'=>20))
				->	addText("總數",$statistfontb,$paracenter);
$tableheadcount ->	addRow(300);
$tableheadcount -> addCell(null, array('vMerge' => 'continue', 'valign'=>'center','borderColor' => '000000','borderBottomSize'=>20,'borderLeftSize'=>20,'borderRightSize'=>10));
$tableheadcount -> addCell(null, array('vMerge' => 'continue', 'valign'=>'center','borderColor' => '000000','borderBottomSize'=>20,'borderLeftSize'=>10,'borderRightSize'=>20));
$tableheadcount ->	addCell(700, array( 'valign'=>'center','borderColor' => '000000','borderBottomSize'=>20,'borderLeftSize'=>20,'borderRightSize'=>10))
				->	addText("男",$statistfontb,$paracenter);
$tableheadcount ->	addCell(700, array( 'valign'=>'center','borderColor' => '000000','borderBottomSize'=>20,'borderLeftSize'=>10,'borderRightSize'=>10))
				->	addText("女",$statistfontb,$paracenter);
$tableheadcount ->	addCell(800, array( 'valign'=>'center','borderColor' => '000000','borderBottomSize'=>20,'borderLeftSize'=>10,'borderRightSize'=>20))
				->	addText("總數",$statistfontb,$paracenter);
$tableheadcount ->	addCell(700, array( 'valign'=>'center','borderColor' => '000000','borderBottomSize'=>20,'borderLeftSize'=>20,'borderRightSize'=>10))
				->	addText("男",$statistfontb,$paracenter);
$tableheadcount ->	addCell(700, array( 'valign'=>'center','borderColor' => '000000','borderBottomSize'=>20,'borderLeftSize'=>10,'borderRightSize'=>10))
				->	addText("女",$statistfontb,$paracenter);
$tableheadcount ->	addCell(800, array( 'valign'=>'center','borderColor' => '000000','borderBottomSize'=>20,'borderLeftSize'=>10,'borderRightSize'=>20))
				->	addText("總數",$statistfontb,$paracenter);
$tableheadcount ->	addCell(700, array( 'valign'=>'center','borderColor' => '000000','borderBottomSize'=>20,'borderLeftSize'=>20,'borderRightSize'=>10))
				->	addText("男",$statistfontb,$paracenter);
$tableheadcount ->	addCell(700, array( 'valign'=>'center','borderColor' => '000000','borderBottomSize'=>20,'borderLeftSize'=>10,'borderRightSize'=>10))
				->	addText("女",$statistfontb,$paracenter);
$tableheadcount ->	addCell(800, array( 'valign'=>'center','borderColor' => '000000','borderBottomSize'=>20,'borderLeftSize'=>10,'borderRightSize'=>20))
				->	addText("總數",$statistfontb,$paracenter);
$tableheadcount -> addCell(null, array('vMerge' => 'continue', 'valign'=>'center','borderColor' => '000000','borderBottomSize'=>20,'borderLeftSize'=>20,'borderRightSize'=>20));
//content
$amt = 0; //Grade A total boy
$aft = 0; //Grade A total girl
$bmt = 0; //Grade B total boy
$bft = 0; //Grade B total girl
$cmt = 0; //Grade C total boy
$cft = 0; //Grade C total girl
$sql = mysqli_query($splink,"Select SCHHOUSE from studentinfo GROUP by SCHHOUSE");
while ($row = mysqli_fetch_row($sql)){
	$tableheadcount ->	addRow(300);  //開新行
	if ($row[0] == "R") {
		$hsename = $txthouseRed;
	} else if ($row[0] == "Y") {
		$hsename = $txthouseYellow;
	} else if ($row[0] == "B") {
		$hsename = $txthouseBlue;
	} else {
		$hsename = $txthouseGreen;
	}
	$tableheadcount ->	addCell(1000,$borderbot10lef20)	->	addText($row[0],$statistfontb,$paracenter);
	$tableheadcount ->	addCell(1200, $borderbot10lef10)->	addText($hsename,$statistfontb,$paracenter);
	$hmt = 0;
	$hft = 0;
	$csql = mysqli_query($splink,"Select A.STUID from APPLICATION_COMPETITION AS A inner JOIN studentinfo AS B on A.STUID=B.STUID where B.SCHHOUSE=\"".$row[0]."\" AND SEX=\"M\" AND LEFT(B.DOB,4 ) < \"".$gradeByr."\"");
	$hmt = mysqli_num_rows($csql);
	$amt = $amt + $hmt;
	$tableheadcount ->	addCell(700, $borderbot10lef20) ->	addText($hmt,$statistfont, $paracenter);
	$csql = mysqli_query($splink,"Select A.STUID from APPLICATION_COMPETITION AS A inner JOIN studentinfo AS B on A.STUID=B.STUID where B.SCHHOUSE=\"".$row[0]."\" AND SEX=\"F\" AND LEFT(B.DOB,4 ) < \"".$gradeByr."\"");
	$hft = mysqli_num_rows($csql);
	$aft = $aft + $hft;
	$tableheadcount ->	addCell(700, $borderbot10lef10) ->	addText($hft,$statistfont, $paracenter);
	$tableheadcount ->	addCell(800, $borderbot10lef10) ->	addText($hmt + $hft,$statistfontb, $paracenter);
	$hmt = 0;
	$hft = 0;
	$csql = mysqli_query($splink,"Select A.STUID from APPLICATION_COMPETITION AS A inner JOIN studentinfo AS B on A.STUID=B.STUID where B.SCHHOUSE=\"".$row[0]."\" AND SEX=\"M\" AND LEFT(B.DOB,4 ) >= \"".$gradeByr."\" AND LEFT(B.DOB,4 ) < \"".$gradeCyr."\"");
	$hmt = mysqli_num_rows($csql);
	$bmt = $bmt + $hmt;
	$tableheadcount ->	addCell(700, $borderbot10lef20) ->	addText($hmt,$statistfont, $paracenter);
	$csql = mysqli_query($splink,"Select A.STUID from APPLICATION_COMPETITION AS A inner JOIN studentinfo AS B on A.STUID=B.STUID where B.SCHHOUSE=\"".$row[0]."\" AND SEX=\"F\" AND LEFT(B.DOB,4 ) >= \"".$gradeByr."\" AND LEFT(B.DOB,4 ) <= \"".$gradeCyr."\"");
	$hft = mysqli_num_rows($csql);
	$bft = $bft + $hft;
	$tableheadcount ->	addCell(700, $borderbot10lef10) ->	addText($bft,$statistfont, $paracenter);
	$tableheadcount ->	addCell(800, $borderbot10lef10) ->	addText($hmt + $hft,$statistfontb, $paracenter);
	$hmt = 0;
	$hft = 0;
	$csql = mysqli_query($splink,"Select A.STUID from APPLICATION_COMPETITION AS A inner JOIN studentinfo AS B on A.STUID=B.STUID where B.SCHHOUSE=\"".$row[0]."\" AND SEX=\"M\" AND LEFT(B.DOB,4 ) >= \"".$gradeCyr."\"");
	$hmt = mysqli_num_rows($csql);
	$cmt = $cmt + $hmt;
	$tableheadcount ->	addCell(700, $borderbot10lef20) ->	addText($hmt,$statistfont, $paracenter);
	$csql = mysqli_query($splink,"Select A.STUID from APPLICATION_COMPETITION AS A inner JOIN studentinfo AS B on A.STUID=B.STUID where B.SCHHOUSE=\"".$row[0]."\" AND SEX=\"F\" AND LEFT(B.DOB,4 ) >= \"".$gradeCyr."\"");
	$hft = mysqli_num_rows($csql);
	$cft = $cft + $hft;
	$tableheadcount ->	addCell(700, $borderbot10lef10) ->	addText($hft,$statistfont, $paracenter);
	$tableheadcount ->	addCell(800, $borderbot10lef10) ->	addText($hmt + $hft,$statistfontb, $paracenter);
	$tableheadcount ->	addCell(1200, $borderbot20lef20rig20) ->	addText($hmt+$hft+$hmt+$hft+$hmt + $hft,$statistfontb, $paracenter);

}
$tableheadcount ->	addRow(300);  //開新行
$tableheadcount ->	addCell(1000, array('borderColor' => '000000','borderTopSize'=>20));
$tableheadcount ->	addCell(1200, array('borderColor' => '000000','borderTopSize'=>20));
$tableheadcount ->	addCell(700, $bordertop20bot20lef20) ->	addText($amt,$statistfont,$paracenter);
$tableheadcount ->	addCell(700, $bordertop20bot20lef10) ->	addText($aft,$statistfont,$paracenter);
$tableheadcount ->	addCell(800, $bordertop20bot20lef10) ->	addText($amt+$aft,$statistfontb,$paracenter);
$tableheadcount ->	addCell(700, $bordertop20bot20lef20) ->	addText($bmt,$statistfont,$paracenter);
$tableheadcount ->	addCell(700, $bordertop20bot20lef10) ->	addText($bft,$statistfont,$paracenter);
$tableheadcount ->	addCell(800, $bordertop20bot20lef10) ->	addText($bmt+$bft,$statistfontb,$paracenter);
$tableheadcount ->	addCell(700, $bordertop20bot20lef20) ->	addText($cmt,$statistfont,$paracenter);
$tableheadcount ->	addCell(700, $bordertop20bot20lef10) ->	addText($cft,$statistfont,$paracenter);
$tableheadcount ->	addCell(800, $bordertop20bot20lef10) ->	addText($cmt+$cft,$statistfontb,$paracenter);
$tableheadcount ->	addCell(1200, $borderall20) ->	addText($amt+$aft+$bmt+$bft+$cmt+$cft,$statistfontb,$paracenter);

$section->	addText('各班別報名參加人數及人次統計',$font16u,$parastatistsheader);
$cpp = 0;	//報名人數
$chc = 0;	//報名人次
$sql = mysqli_query($splink,"Select CLASSCODE from studentinfo where LEFT(CLASSCODE,1)  < 5 group by CLASSCODE ORDER BY CLASSCODE");
while ($row = mysqli_fetch_row($sql)){
	$class14[]=$row[0];
	$csql = mysqli_query($splink,"Select A.STUID from APPLICATION_COMPETITION AS A inner JOIN studentinfo AS B on A.STUID=B.STUID where B.CLASSCODE=\"".$row[0]."\" GROUP BY A.STUID");
	$noofp14[] = mysqli_num_rows($csql);
	$cpp = $cpp + mysqli_num_rows($csql);
	$csql = mysqli_query($splink,"Select A.STUID from APPLICATION_COMPETITION AS A inner JOIN studentinfo AS B on A.STUID=B.STUID where B.CLASSCODE=\"".$row[0]."\"");
	$noofh14[] = mysqli_num_rows($csql);
	$chc = $chc + mysqli_num_rows($csql);
}

$sql = mysqli_query($splink,"Select CLASSCODE from studentinfo where LEFT(CLASSCODE,1)  >= 5 group by CLASSCODE ORDER BY CLASSCODE");
while ($row = mysqli_fetch_row($sql)){
	$class56[]=$row[0];
	$csql = mysqli_query($splink,"Select A.STUID from APPLICATION_COMPETITION AS A inner JOIN studentinfo AS B on A.STUID=B.STUID where B.CLASSCODE=\"".$row[0]."\" GROUP BY A.STUID");
	$noofp56[] = mysqli_num_rows($csql);
	$cpp = $cpp + mysqli_num_rows($csql);
	$csql = mysqli_query($splink,"Select A.STUID from APPLICATION_COMPETITION AS A inner JOIN studentinfo AS B on A.STUID=B.STUID where B.CLASSCODE=\"".$row[0]."\"");
	$noofh56[] = mysqli_num_rows($csql);
	$chc = $chc + mysqli_num_rows($csql);
}

$tableclasscount = $section->addTable($contentTableStyle);
$tableclasscount ->	addRow(300);
$tableclasscount ->	addCell(1000,$borderall20)	->	addText("班別",$statistfontb,$paracenter);
$tableclasscount ->	addCell(1500,$bordertop20bot20lef20)	->	addText("報名人數",$statistfontb,$paracenter);
$tableclasscount ->	addCell(1500,$bordertop20bot20lef10rig20)	->	addText("報名人次",$statistfontb,$paracenter);
$tableclasscount ->	addCell(500)				->	addText("");
$tableclasscount ->	addCell(1000,$borderall20)	->	addText("班別",$statistfontb,$paracenter);
$tableclasscount ->	addCell(1500,$bordertop20bot20lef20)	->	addText("報名人數",$statistfontb,$paracenter);
$tableclasscount ->	addCell(1500,$bordertop20bot20lef10rig20)	->	addText("報名人次",$statistfontb,$paracenter);
$x = 0;
while ($x < sizeof($class14)) {
	$tableclasscount -> addRow(300);
	if ($x == sizeof($class14) -1 ) {
		$xcbor = $borderbot20lef20rig20;
		$xpbor = $borderbot20lef20;
		$xhbor = $borderbot20lef10rig20;
	} else {
		$xcbor = $borderbot10lef20rig20;
		$xpbor = $borderbot10lef20;
		$xhbor = $borderbot10lef10rig20;
	}
	$tableclasscount -> addCell(1000,$xcbor) ->	addText($class14[$x],$statistfontb,$paracenter);
	$tableclasscount -> addCell(1500,$xpbor) ->	addText($noofp14[$x],$statistfont,$paracenter);
	$tableclasscount -> addCell(1500,$xhbor) ->	addText($noofh14[$x],$statistfont,$paracenter);
	if ($x < sizeof($class56)) {
		$tableclasscount -> addCell(500)	->	addText("");
		if ($x == sizeof($class56) -1 ) {
			$xcbor = $borderbot20lef20rig20;
			$xpbor = $borderbot20lef20;
			$xhbor = $borderbot20lef10rig20;
		} else {
			$xcbor = $borderbot10lef20rig20;
			$xpbor = $borderbot10lef20;
			$xhbor = $borderbot10lef10rig20;
		}
		$tableclasscount -> addCell(1000,$xcbor) ->	addText($class56[$x],$statistfontb,$paracenter);
		$tableclasscount -> addCell(1500,$xpbor) ->	addText($noofp56[$x],$statistfont,$paracenter);
		$tableclasscount -> addCell(1500,$xhbor) ->	addText($noofh56[$x],$statistfont,$paracenter);
		
	} else if ($x == sizeof($class56)){
		$tableclasscount -> addCell(500)	->	addText("");
		$tableclasscount -> addCell(1000,$borderall20) ->	addText("全校",$statistfontb,$paracenter);
		$tableclasscount -> addCell(1500,$bordertop20bot20lef20) ->	addText($cpp,$statistfont,$paracenter);
		$tableclasscount -> addCell(1500,$bordertop20bot20lef10rig20) ->	addText($chc,$statistfont,$paracenter);
	} else {
		$tableclasscount -> addCell(500)	->	addText("");
		$tableclasscount -> addCell(1000)	->	addText("");
		$tableclasscount -> addCell(1500)	->	addText("");
		$tableclasscount -> addCell(1500)	->	addText("");
	}
	
	$x++;
}


//田項參賽者總表 - 初賽日
$sql = mysqli_query($splink,"Select B.CH_DES, B.SEX, B.GRADE , A.ORDER_ID,A.HeatorFinal,A.COMPETITION_ID,A.EVENTTIME from COMPETITION_DATEID AS A inner join COMPETITIONITEM AS B ON A.COMPETITION_ID=B.keyid where A.DATE=\"".$startday."\" AND B.TRACKFIELD=\"2\" ORDER BY A.ORDER_ID");
$x = 0;
$y = 0;
while ($row = mysqli_fetch_row($sql)){
	if (is_int($x/4) || $x == 0) {
		$section->	addPageBreak();
		$section	->	addText("初賽日", $font18,$pararight);
		$section-> addText($company,$font14,$paracenter);
		$section-> addText($sportdayname,$font14,$paracenter);
		$section->	addText('田項參賽者總表',$font14,$parastatistsheader);
		$section->	addTextBreak();
		$tablebname = "tablefieldapp".$y;
		$$tablebname = $section ->	addTable($contentTableStyle);
		$$tablebname ->	addRow();
		$x = 0;
		$y++;
	}
	if ($row[4] == 0 ) {
		$horf = $txt1stheat;
	} else {
		$horf = $txtfinal;
	}
	if ($row[1] == 1) {
		$sex = $txtboy."子";
	} else if ( $row[1] == 2) {
		$sex = $txtgirl."子";
	} else {
		$sex = "";
	}
	if ($row[2] == "A"){
		$grade = $txtgradeA;
	} else if ($row[2] == "B" ) {
		$grade = $txtgradeB;
	} else if ($row[2] == "C" ){
		$grade = $txtgradeC;
	} else {
		$grade = "";
	}
		
		$cell = "cell".$y.$x;
		$$cell = $$tablebname -> addCell(2500,array('borderColor' => '000000','borderTopSize' => 15));
		$$cell -> addTextBreak();
		$intable = "intable".$row[3];
		$$intable = $$cell ->addTable($contentTableStyle);
		$$intable ->	addRow(200);
		$$intable ->	addCell(1000, array('gridSpan' => 2, 'valign'=>'center'))	-> addText("項目(".$row[3].")",$font10);
		$$intable ->	addCell(1000,$applisthfstyleu)	-> addText($horf,$bold18,$paracenter);
		$$intable ->	addRow(200);
		$$intable ->	addCell(1000, array('gridSpan' => 2, 'valign'=>'center'))	->	addText("時間：".$row[6],$font10); 
		$$intable ->	addCell(null,$applisthfstyleb);
		$$intable ->	addRow(200);
		$$intable ->	addCell(2000, array('gridSpan' => 4, 'valign'=>'center')) -> addText($row[0],$font10);
		$$intable ->	addRow(200);
		$$intable ->	addCell(2000, array('gridSpan' => 4, 'valign'=>'center')) -> addText($sex.$grade,$font10);
		$$intable ->	addRow(200);
		$$intable ->	addCell(430, $borderall10) -> addText("次序",$font10,$paracenter);
		$$intable ->	addCell(470, $borderall10) -> addText("班號",$font10,$paracenter);
		$$intable ->	addCell(850, $borderall10) -> addText("姓名",$font10,$paracenter);
		$$intable ->	addCell(250, $borderall10) -> addText("社",$font10,$paracenter);
		$esql = mysqli_query($splink,"Select B.CLASSCODE, B.CLASSNO, B.CHNAME, B.SCHHOUSE from APPLICATION_COMPETITION AS A inner join studentinfo AS B ON A.STUID=B.STUID where A.COMPETITION_ID=\"".$row[5]."\" ORDER BY B.CLASSCODE, B.CLASSNO");
		$tt = 1;
		while ($erow = mysqli_fetch_row($esql)){
			if (is_int(($tt-1)/40) && $tt !== 1 ) {
				$x++;
				if ($x == 4) {
					$y++;
					$section->	addPageBreak();
					$section	->	addText("初賽日", $font18,$pararight);
					$section-> addText($company,$font14,$paracenter);
					$section-> addText($sportdayname,$font14,$paracenter);
					$section->	addText('田項參賽者總表',$font14,$parastatistsheader);
					$section->	addTextBreak();
					$tablebname = "tablefieldapp".$y;
					$$tablebname = $section ->	addTable($contentTableStyle);
					$$tablebname ->	addRow();
					$x = 0;
				}
				$cell = "cell".$y.$x.$tt;
				$$cell = $$tablebname -> addCell(2500,array('borderColor' => '000000','borderTopSize' => 15));
				$$cell -> addTextBreak();
				$intable = "intable".$row[3].$tt;
				$$intable = $$cell ->addTable($contentTableStyle);
				$$intable ->	addRow(200);
				$$intable ->	addCell(1000, array('gridSpan' => 2, 'valign'=>'center'))	-> addText("項目(".$row[3].")",$font10);
				$$intable ->	addCell(1000,$applisthfstyleu)	-> addText($horf,$bold18,$paracenter);
				$$intable ->	addRow(200);
				$$intable ->	addCell(1000, array('gridSpan' => 2, 'valign'=>'center'))	->	addText("時間：".$row[6],$font10); 
				$$intable ->	addCell(null,$applisthfstyleb);
				$$intable ->	addRow(200);
				$$intable ->	addCell(2000, array('gridSpan' => 4, 'valign'=>'center')) -> addText($row[0],$font10);
				$$intable ->	addRow(200);
				$$intable ->	addCell(2000, array('gridSpan' => 4, 'valign'=>'center')) -> addText($sex.$grade,$font10);
				$$intable ->	addRow(200);
				$$intable ->	addCell(430, $borderall10) -> addText("次序",$font10,$paracenter);
				$$intable ->	addCell(470, $borderall10) -> addText("班號",$font10,$paracenter);
				$$intable ->	addCell(850, $borderall10) -> addText("姓名",$font10,$paracenter);
				$$intable ->	addCell(250, $borderall10) -> addText("社",$font10,$paracenter);
				
			}
			$$intable ->	addRow(200);
			$$intable ->	addCell(430, $borderall10) -> addText($tt,$font10,$paracenter);
			$$intable ->	addCell(470, $borderall10) -> addText($erow[0]."-".$erow[1],$font10,$paracenter);
			$$intable ->	addCell(850, $borderall10) -> addText($erow[2],$font10,$paracenter);
			$$intable ->	addCell(250, $borderall10) -> addText($erow[3],$font10,$paracenter);
			$tt++;
		}
	$x++;
}

//田項參賽者總表 - 決賽日
$sql = mysqli_query($splink,"Select B.CH_DES, B.SEX, B.GRADE , A.ORDER_ID,A.HeatorFinal,A.COMPETITION_ID,A.EVENTTIME from COMPETITION_DATEID AS A inner join COMPETITIONITEM AS B ON A.COMPETITION_ID=B.keyid where A.DATE=\"".$endday."\" AND B.TRACKFIELD=\"2\" ORDER BY A.ORDER_ID");
$x = 0;
$y = 0;
while ($row = mysqli_fetch_row($sql)){
	if (is_int($x/4) || $x == 0) {
		$section->	addPageBreak();
		$section	->	addText("決賽日", $font18,$pararight);
		$section-> addText($company,$font14,$paracenter);
		$section-> addText($sportdayname,$font14,$paracenter);
		$section->	addText('田項參賽者總表',$font14,$parastatistsheader);
		$section->	addTextBreak();
		$tablebname = "tablefieldapp".$y;
		$$tablebname = $section ->	addTable($contentTableStyle);
		$$tablebname ->	addRow();
		$x = 0;
		$y++;
	}
	if ($row[4] == 0 ) {
		$horf = $txt1stheat;
	} else {
		$horf = $txtfinal;
	}
	if ($row[1] == 1) {
		$sex = $txtboy."子";
	} else if ( $row[1] == 2) {
		$sex = $txtgirl."子";
	} else {
		$sex = "";
	}
	if ($row[2] == "A"){
		$grade = $txtgradeA;
	} else if ($row[2] == "B" ) {
		$grade = $txtgradeB;
	} else if ($row[2] == "C" ){
		$grade = $txtgradeC;
	} else {
		$grade = "";
	}
		
		$cell = "cell".$y.$x;
		$$cell = $$tablebname -> addCell(2500,array('borderColor' => '000000','borderTopSize' => 15));
		$$cell -> addTextBreak();
		$intable = "intable".$row[3];
		$$intable = $$cell ->addTable($contentTableStyle);
		$$intable ->	addRow(200);
		$$intable ->	addCell(1000, array('gridSpan' => 2, 'valign'=>'center'))	-> addText("項目(".$row[3].")",$font10);
		$$intable ->	addCell(1000,$applisthfstyleu)	-> addText($horf,$bold18,$paracenter);
		$$intable ->	addRow(200);
		$$intable ->	addCell(1000, array('gridSpan' => 2, 'valign'=>'center'))	->	addText("時間：".$row[6],$font10); 
		$$intable ->	addCell(null,$applisthfstyleb);
		$$intable ->	addRow(200);
		$$intable ->	addCell(2000, array('gridSpan' => 4, 'valign'=>'center')) -> addText($row[0],$font10);
		$$intable ->	addRow(200);
		$$intable ->	addCell(2000, array('gridSpan' => 4, 'valign'=>'center')) -> addText($sex.$grade,$font10);
		$$intable ->	addRow(200);
		$$intable ->	addCell(430, $borderall10) -> addText("次序",$font10,$paracenter);
		$$intable ->	addCell(470, $borderall10) -> addText("班號",$font10,$paracenter);
		$$intable ->	addCell(850, $borderall10) -> addText("姓名",$font10,$paracenter);
		$$intable ->	addCell(250, $borderall10) -> addText("社",$font10,$paracenter);
		$esql = mysqli_query($splink,"Select B.CLASSCODE, B.CLASSNO, B.CHNAME, B.SCHHOUSE from APPLICATION_COMPETITION AS A inner join studentinfo AS B ON A.STUID=B.STUID where A.COMPETITION_ID=\"".$row[5]."\" ORDER BY B.CLASSCODE, B.CLASSNO");
		$tt = 1;
		while ($erow = mysqli_fetch_row($esql)){
			if (is_int(($tt-1)/40) && $tt !== 1 ) {
				$x++;
				if ($x == 4) {
					$y++;
					$section->	addPageBreak();
					$section	->	addText("決賽日", $font18,$pararight);
					$section-> addText($company,$font14,$paracenter);
					$section-> addText($sportdayname,$font14,$paracenter);
					$section->	addText('田項參賽者總表',$font14,$parastatistsheader);
					$section->	addTextBreak();
					$tablebname = "tablefieldapp".$y;
					$$tablebname = $section ->	addTable($contentTableStyle);
					$$tablebname ->	addRow();
					$x = 0;
				}
				$cell = "cell".$y.$x.$tt;
				$$cell = $$tablebname -> addCell(2500,array('borderColor' => '000000','borderTopSize' => 15));
				$$cell -> addTextBreak();
				$intable = "intable".$row[3].$tt;
				$$intable = $$cell ->addTable($contentTableStyle);
				$$intable ->	addRow(200);
				$$intable ->	addCell(1000, array('gridSpan' => 2, 'valign'=>'center'))	-> addText("項目(".$row[3].")",$font10);
				$$intable ->	addCell(1000,$applisthfstyleu)	-> addText($horf,$bold18,$paracenter);
				$$intable ->	addRow(200);
				$$intable ->	addCell(1000, array('gridSpan' => 2, 'valign'=>'center'))	->	addText("時間：",$font10); 
				$$intable ->	addCell(null,$applisthfstyleb);
				$$intable ->	addRow(200);
				$$intable ->	addCell(2000, array('gridSpan' => 4, 'valign'=>'center')) -> addText($row[0],$font10);
				$$intable ->	addRow(200);
				$$intable ->	addCell(2000, array('gridSpan' => 4, 'valign'=>'center')) -> addText($sex.$grade,$font10);
				$$intable ->	addRow(200);
				$$intable ->	addCell(430, $borderall10) -> addText("次序",$font10,$paracenter);
				$$intable ->	addCell(470, $borderall10) -> addText("班號",$font10,$paracenter);
				$$intable ->	addCell(850, $borderall10) -> addText("姓名",$font10,$paracenter);
				$$intable ->	addCell(250, $borderall10) -> addText("社",$font10,$paracenter);
				
			}
			$$intable ->	addRow(200);
			$$intable ->	addCell(430, $borderall10) -> addText($tt,$font10,$paracenter);
			$$intable ->	addCell(470, $borderall10) -> addText($erow[0]."-".$erow[1],$font10,$paracenter);
			$$intable ->	addCell(850, $borderall10) -> addText($erow[2],$font10,$paracenter);
			$$intable ->	addCell(250, $borderall10) -> addText($erow[3],$font10,$paracenter);
			$tt++;
		}
	$x++;
}

//田項參賽者總表 - 初賽日
$section->	addPageBreak();
$section	->	addText("初賽日", $font18,$pararight);
$section-> addText($company,$font14,$paracenter);
$section-> addText($sportdayname,$font14,$paracenter);
$section->	addText('徑項參賽者總表',$font14,$parastatistsheader);
$tablebtrackh = $section ->	addTable($contentTableStyle);
$tablebtrackh ->	addRow();
$tablebtrackh ->	addCell(10000,$tracktabletitle);
$section	-> addTextBreak();

$sql = mysqli_query($splink,"Select B.CH_DES, B.SEX, B.GRADE , A.ORDER_ID,A.HeatorFinal,A.COMPETITION_ID,A.EVENTTIME from COMPETITION_DATEID AS A inner join COMPETITIONITEM AS B ON A.COMPETITION_ID=B.keyid where A.DATE=\"".$startday."\" AND B.TRACKFIELD=\"1\" AND B.INTERHOUSE=\"0\" AND INTERCLASS=\"0\" ORDER BY A.ORDER_ID");
while ($row = mysqli_fetch_row($sql)){
	if ($row[4] == 0 ) {
		$horf = $txt1stheat;
	} else {
		$horf = $txtfinal;
	}
	if ($row[1] == 1) {
		$sex = $txtboy."子";
	} else if ( $row[1] == 2) {
		$sex = $txtgirl."子";
	} else {
		$sex = "";
	}
	if ($row[2] == "A"){
		$grade = $txtgradeA;
	} else if ($row[2] == "B" ) {
		$grade = $txtgradeB;
	} else if ($row[2] == "C" ){
		$grade = $txtgradeC;
	} else {
		$grade = "";
	}
	$tablename = "tabletrack".$row[3];	
	$$tablename = $section	->	addTable($contentTableStyle);
	$$tablename ->	addRow(200);
	$$tablename	->	addCell(900,array('valign' => 'center', 'borderColor' => '000000', 'borderTopSize' => 15,'borderBottomSize' => 15,'borderLeftSize' => 15,'borderRightSize' => 15))
					->	addText("項目(".$row[3].")",$font10,$paracenter);
	$$tablename ->	addCell(2100,array('gridSpan' => 2))
				->	addText("時間：".$row[6],$font10, $paracenter);
	$$tablename	->	addCell(3150,array('gridSpan' => 3,'valign' => 'center'))
					->	addText($row[0],$font10,$paracenter);
	$$tablename	->	addCell(2100,array('gridSpan' => 2, 'valign' => 'center'))
					->	addText($sex.$grade,$font10,$paracenter);
	$$tablename	->	addCell(1050,array('valign' => 'center', 'borderColor' => '000000', 'borderTopSize' => 15,'borderBottomSize' => 15,'borderLeftSize' => 15,'borderRightSize' => 15))
					->	addText($horf,$font10,$paracenter);
	$$tablename ->	addRow(400);
	$$tablename	->	addCell(900,$tracktabletitle) 	->	addText("組",$font10, $paracenter);
	$$tablename	->	addCell(1050,$tracktabletitle) 	->	addText("線道一",$font10, $paracenter);
	$$tablename	->	addCell(1050,$tracktabletitle) 	->	addText("線道二",$font10, $paracenter);
	$$tablename	->	addCell(1050,$tracktabletitle) 	->	addText("線道三",$font10, $paracenter);
	$$tablename	->	addCell(1050,$tracktabletitle) 	->	addText("線道四",$font10, $paracenter);
	$$tablename	->	addCell(1050,$tracktabletitle) 	->	addText("線道五",$font10, $paracenter);
	$$tablename	->	addCell(1050,$tracktabletitle) 	->	addText("線道六",$font10, $paracenter);
	$$tablename	->	addCell(1050,$tracktabletitle) 	->	addText("線道七",$font10, $paracenter);
	$$tablename	->	addCell(1050,$tracktabletitle) 	->	addText("線道八",$font10, $paracenter);

	$esql = mysqli_query($splink,"Select * from TRACKEVENT_HEAT_LANE where COMPETITION_ID=\"".$row[5]."\"");
	if (mysqli_num_rows($esql) > 0 ) {
		$idsql = mysqli_query($splink,"Select EVENT_ID from TRACKEVENT_HEAT_LANE WHERE COMPETITION_ID=\"".$row[5]."\" group BY EVENT_ID");
		$x = 1;
		$noofid = mysqli_num_rows($idsql);
		while ($idrow = mysqli_fetch_row($idsql)){
			if ($x == $noofid){
				$rowb = $borderbot20lef20;
				$rowp = $borderbot20lef10;
				$rowl = $borderbot20lef10rig20;
			} else {
				$rowb = $borderbot10lef20;
				$rowp = $borderbot10lef10;
				$rowl = $borderbot10lef10rig20;
			}
			$$tablename ->	addRow(400);
			$$tablename -> addCell(900,$rowb)	->	addText($x,$font10,$paracenter);
			$y = 1;
			while ($y < 9 ) {
				$asql = mysqli_query($splink,"Select B.CHNAME, B.CLASSCODE, B.CLASSNO, B.SCHHOUSE from TRACKEVENT_HEAT_LANE AS A inner join studentinfo AS B on A.STUID=B.STUID where A.COMPETITION_ID=\"".$row[5]."\" AND A.EVENT_ID=\"".$idrow[0]."\" AND A.LANE_NO =\"".$y."\" ORDER BY A.LANE_NO");
				if (mysqli_num_rows($asql) > 0 ) {
					while ($arow = mysqli_fetch_row($asql)){
						$celln = "cell".$row[5]."a".$x."b".$y;
						if ($y == 8 ){
							$$celln = $$tablename ->	addCell(1050,$rowl);
						} else {
							$$celln = $$tablename ->	addCell(1050,$rowp);
						}
						$textn = "text".$row[5]."a".$x."b".$y;

//						$$textn = $$celln	-> addTextRun(array('alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER));
						$$celln ->	addText($arow[0],$font10,$paracenter);
						$$celln ->	addText($arow[1]."(".$arow[2].") ".$arow[3],$font10,$paracenter);
					}
				} else {
					if ($y == 8 ){
						$$tablename ->	addCell(1050,$rowl) ->	addText("",$font10);
					} else {
						$$tablename ->	addCell(1050,$rowp) ->	addText("",$font10);
					}
				}
				$y++;
			}
		$x++;
		}
		$$tablename ->	addRow(400);
		$$tablename	->	addCell(900, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
		$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
		$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
		$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
		$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
		$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
		$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
		$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
		$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
		
	} else {
		$asql = mysqli_query($splink,"Select B.CHNAME, B.CLASSCODE, B.CLASSNO, B.SCHHOUSE from APPLICATION_COMPETITION AS A inner join studentinfo AS B on A.STUID=B.STUID where A.COMPETITION_ID=\"".$row[5]."\" AND A.SCHYEAR=\"".$todayschyr."\" ORDER BY B.CLASSCODE, B.CLASSNO");
		$noofstud = mysqli_num_rows($asql);
		$noofrow = floor($noofstud / 8) + 1;
		$x = 1;
		if ($x == $noofrow){
			$rowb = $borderbot20lef20;
			$rowp = $borderbot20lef10;
			$rowl = $borderbot20lef10rig20;
		} else {
			$rowb = $borderbot10lef20;
			$rowp = $borderbot10lef10;
			$rowl = $borderbot10lef10rig20;
		}

		$$tablename ->	addRow(400);
		$$tablename -> addCell(900,$rowb);
		$y = 1;
		while ($arow = mysqli_fetch_row($asql)){
			$celln = "cell".$row[5]."a".$x."b".$y;
			if ($y == 9) {
				$x++;
				if ($x == $noofrow){
					$rowb = $borderbot20lef20;
					$rowp = $borderbot20lef10;
					$rowl = $borderbot20lef10rig20;
				} else {
					$rowb = $borderbot10lef20;
					$rowp = $borderbot10lef10;
					$rowl = $borderbot10lef10rig20;
				}
				$$tablename -> addRow(400);
				$$tablename	->	addCell(900,$rowb);
				$y =1;
			}
			if ($y == 8 ){
				$$celln = $$tablename ->	addCell(1050,$rowl);
			} else {
				$$celln = $$tablename ->	addCell(1050,$rowp);
			}
//			$textn = "text".$row[5]."a".$x."b".$y;
	//		$$textn = $$celln	-> addTextRun(array('alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER));
			$$celln ->	addText($arow[0],$font10,$paracenter);
			$$celln ->	addText($arow[1]."(".$arow[2].") ".$arow[3],$font10,$paracenter);
			$y++;
		}
		$leftc = 8 - $y +1;
		$tt = 0;
		while ($tt < $leftc ) {
			if ($tt == $leftc -1 ){
				$$tablename ->	addCell(1050,$rowl) ->	addText("",$font10);
			} else {
				$$tablename ->	addCell(1050,$rowp) ->	addText("".$leftc,$font10);
			}
			$tt++;
		}
		$$tablename ->	addRow(400);
		$$tablename	->	addCell(900, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
		$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
		$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
		$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
		$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
		$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
		$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
		$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
		$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
	}
	$section	-> addTextBreak();				
}
//社際
$sql = mysqli_query($splink,"Select B.CH_DES, B.SEX, B.GRADE , A.ORDER_ID,A.HeatorFinal,A.COMPETITION_ID from COMPETITION_DATEID AS A inner join COMPETITIONITEM AS B ON A.COMPETITION_ID=B.keyid where A.DATE=\"".$startday."\" AND B.TRACKFIELD=\"1\" AND B.INTERHOUSE=\"1\" AND INTERCLASS=\"0\" ORDER BY A.ORDER_ID");
while ($row = mysqli_fetch_row($sql)){
	if ($row[4] == 0 ) {
		$horf = $txt1stheat;
	} else {
		$horf = $txtfinal;
	}
	if ($row[1] == 1) {
		$sex = $txtboy."子";
	} else if ( $row[1] == 2) {
		$sex = $txtgirl."子";
	} else {
		$sex = "";
	}
	if ($row[2] == "A"){
		$grade = $txtgradeA;
	} else if ($row[2] == "B" ) {
		$grade = $txtgradeB;
	} else if ($row[2] == "C" ){
		$grade = $txtgradeC;
	} else {
		$grade = "";
	}
	$tablename = "tabletrack".$row[3];	
	$$tablename = $section	->	addTable($contentTableStyle);
	$$tablename ->	addRow(200);
	$$tablename	->	addCell(900,array('valign' => 'center', 'borderColor' => '000000', 'borderTopSize' => 15,'borderBottomSize' => 15,'borderLeftSize' => 15,'borderRightSize' => 15))
					->	addText("項目(".$row[3].")",$font10,$paracenter);
	$$tablename ->	addCell(2100,array('gridSpan' => 2))
				->	addText("時間：",$font10, $paracenter);
	$$tablename	->	addCell(3150,array('gridSpan' => 3,'valign' => 'center'))
					->	addText($row[0],$font10,$paracenter);
	$$tablename	->	addCell(2100,array('gridSpan' => 2, 'valign' => 'center'))
					->	addText($sex.$grade,$font10,$paracenter);
	$$tablename	->	addCell(1050,array('valign' => 'center', 'borderColor' => '000000', 'borderTopSize' => 15,'borderBottomSize' => 15,'borderLeftSize' => 15,'borderRightSize' => 15))
					->	addText($horf,$font10,$paracenter);
	$$tablename ->	addRow(400);
	$$tablename	->	addCell(900,$tracktabletitle) 	->	addText("組",$font10, $paracenter);
	$$tablename	->	addCell(1050,$tracktabletitle) 	->	addText("線道一",$font10, $paracenter);
	$$tablename	->	addCell(1050,$tracktabletitle) 	->	addText("線道二",$font10, $paracenter);
	$$tablename	->	addCell(1050,$tracktabletitle) 	->	addText("線道三",$font10, $paracenter);
	$$tablename	->	addCell(1050,$tracktabletitle) 	->	addText("線道四",$font10, $paracenter);
	$$tablename	->	addCell(1050,$tracktabletitle) 	->	addText("線道五",$font10, $paracenter);
	$$tablename	->	addCell(1050,$tracktabletitle) 	->	addText("線道六",$font10, $paracenter);
	$$tablename	->	addCell(1050,$tracktabletitle) 	->	addText("線道七",$font10, $paracenter);
	$$tablename	->	addCell(1050,$tracktabletitle) 	->	addText("線道八",$font10, $paracenter);

	$$tablename ->	addRow(400);
	$$tablename -> addCell(900,$rowb)	->	addText($x,$font10,$paracenter);
	$$tablename	->	addCell(900,$borderbot20lef20);
	$$tablename	->	addCell(1050,$borderbot20lef10) 	->	addText($txthouseRed."A",$font10, $paracenter);
	$$tablename	->	addCell(1050,$borderbot20lef10) 	->	addText($txthouseYellow."A",$font10, $paracenter);
	$$tablename	->	addCell(1050,$borderbot20lef10) 	->	addText($txthouseBlue."A",$font10, $paracenter);
	$$tablename	->	addCell(1050,$borderbot20lef10) 	->	addText($txthouseGreen."A",$font10, $paracenter);
	$$tablename	->	addCell(1050,$borderbot20lef10) 	->	addText($txthouseRed."B",$font10, $paracenter);
	$$tablename	->	addCell(1050,$borderbot20lef10) 	->	addText($txthouseYellow."B",$font10, $paracenter);
	$$tablename	->	addCell(1050,$borderbot20lef10) 	->	addText($txthouseBlue."B",$font10, $paracenter);
	$$tablename	->	addCell(1050,$borderbot20lef10rig20) 	->	addText($txthouseGreen."B",$font10, $paracenter);
	$$tablename ->	addRow(400);
	$$tablename	->	addCell(900, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
	$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
	$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
	$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
	$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
	$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
	$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
	$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
	$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
		
	$section	-> addTextBreak();				
}


//田項參賽者總表 - 決賽日
$section->	addPageBreak();
$section	->	addText("決賽日", $font18,$pararight);
$section-> addText($company,$font14,$paracenter);
$section-> addText($sportdayname,$font14,$paracenter);
$section->	addText('徑項參賽者總表',$font14,$parastatistsheader);
$tablebtrackh = $section ->	addTable($contentTableStyle);
$tablebtrackh ->	addRow();
$tablebtrackh ->	addCell(10000,$tracktabletitle);
$section	-> addTextBreak();

$sql = mysqli_query($splink,"Select B.CH_DES, B.SEX, B.GRADE , A.ORDER_ID,A.HeatorFinal,A.COMPETITION_ID,A.EVENTTIME from COMPETITION_DATEID AS A inner join COMPETITIONITEM AS B ON A.COMPETITION_ID=B.keyid where A.DATE=\"".$endday."\" AND B.TRACKFIELD=\"1\" AND B.INTERHOUSE=\"0\" AND INTERCLASS=\"0\" ORDER BY A.ORDER_ID");
while ($row = mysqli_fetch_row($sql)){
	if ($row[4] == 0 ) {
		$horf = $txt1stheat;
	} else {
		$horf = $txtfinal;
	}
	if ($row[1] == 1) {
		$sex = $txtboy."子";
	} else if ( $row[1] == 2) {
		$sex = $txtgirl."子";
	} else {
		$sex = "";
	}
	if ($row[2] == "A"){
		$grade = $txtgradeA;
	} else if ($row[2] == "B" ) {
		$grade = $txtgradeB;
	} else if ($row[2] == "C" ){
		$grade = $txtgradeC;
	} else {
		$grade = "";
	}

	$esql = mysqli_query($splink,"Select * from TRACKEVENT_HEAT_LANE where COMPETITION_ID=\"".$row[5]."\"");
	if (mysqli_num_rows($esql) > 0 ) {
		$idsql = mysqli_query($splink,"Select EVENT_ID from TRACKEVENT_HEAT_LANE WHERE COMPETITION_ID=\"".$row[5]."\" group BY EVENT_ID");
		$x = 1;
		$noofid = mysqli_num_rows($idsql);
		if ($noofid == 1 ) {
			while ($idrow = mysqli_fetch_row($idsql)){

				$tablename = "tabletrack".$row[3];	
				$$tablename = $section	->	addTable($contentTableStyle);
				$$tablename ->	addRow(200);
				$$tablename	->	addCell(900,array('valign' => 'center', 'borderColor' => '000000', 'borderTopSize' => 15,'borderBottomSize' => 15,'borderLeftSize' => 15,'borderRightSize' => 15))
								->	addText("項目(".$row[3].")",$font10,$paracenter);
				$$tablename ->	addCell(2100,array('gridSpan' => 2))
							->	addText("時間：".$row[6],$font10, $paracenter);
				$$tablename	->	addCell(3150,array('gridSpan' => 3,'valign' => 'center'))
								->	addText($row[0],$font10,$paracenter);
				$$tablename	->	addCell(2100,array('gridSpan' => 2, 'valign' => 'center'))
								->	addText($sex.$grade,$font10,$paracenter);
				$$tablename	->	addCell(1050,array('valign' => 'center', 'borderColor' => '000000', 'borderTopSize' => 15,'borderBottomSize' => 15,'borderLeftSize' => 15,'borderRightSize' => 15))
								->	addText($horf,$font10,$paracenter);
				$$tablename ->	addRow(400);
				$$tablename	->	addCell(900,$tracktabletitle) 	->	addText("組",$font10, $paracenter);
				$$tablename	->	addCell(1050,$tracktabletitle) 	->	addText("線道一",$font10, $paracenter);
				$$tablename	->	addCell(1050,$tracktabletitle) 	->	addText("線道二",$font10, $paracenter);
				$$tablename	->	addCell(1050,$tracktabletitle) 	->	addText("線道三",$font10, $paracenter);
				$$tablename	->	addCell(1050,$tracktabletitle) 	->	addText("線道四",$font10, $paracenter);
				$$tablename	->	addCell(1050,$tracktabletitle) 	->	addText("線道五",$font10, $paracenter);
				$$tablename	->	addCell(1050,$tracktabletitle) 	->	addText("線道六",$font10, $paracenter);
				$$tablename	->	addCell(1050,$tracktabletitle) 	->	addText("線道七",$font10, $paracenter);
				$$tablename	->	addCell(1050,$tracktabletitle) 	->	addText("線道八",$font10, $paracenter);

				if ($x == $noofid){
					$rowb = $borderbot20lef20;
					$rowp = $borderbot20lef10;
					$rowl = $borderbot20lef10rig20;
				} else {
					$rowb = $borderbot10lef20;
					$rowp = $borderbot10lef10;
					$rowl = $borderbot10lef10rig20;
				}
				$$tablename ->	addRow(400);
				$$tablename -> addCell(900,$rowb)	->	addText($x,$font10,$paracenter);
				$y = 1;
				while ($y < 9 ) {
					$asql = mysqli_query($splink,"Select B.CHNAME, B.CLASSCODE, B.CLASSNO, B.SCHHOUSE from TRACKEVENT_HEAT_LANE AS A inner join studentinfo AS B on A.STUID=B.STUID where A.COMPETITION_ID=\"".$row[5]."\" AND A.EVENT_ID=\"".$idrow[0]."\" AND A.LANE_NO =\"".$y."\" ORDER BY A.LANE_NO");
					if (mysqli_num_rows($asql) > 0 ) {
						while ($arow = mysqli_fetch_row($asql)){
							$celln = "cell".$row[5]."a".$x."b".$y;
							if ($y == 8 ){
								$$celln = $$tablename ->	addCell(1050,$rowl);
							} else {
								$$celln = $$tablename ->	addCell(1050,$rowp);
							}
							$textn = "text".$row[5]."a".$x."b".$y;
	
	//						$$textn = $$celln	-> addTextRun(array('alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER));
							$$celln ->	addText($arow[0],$font10,$paracenter);
							$$celln ->	addText($arow[1]."(".$arow[2].") ".$arow[3],$font10,$paracenter);
						}
					} else {
						if ($y == 8 ){
							$$tablename ->	addCell(1050,$rowl) ->	addText("",$font10);
						} else {
							$$tablename ->	addCell(1050,$rowp) ->	addText("",$font10);
						}
					}
					$y++;
				}
			$x++;
			}
			$$tablename ->	addRow(400);
			$$tablename	->	addCell(900, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
			$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
			$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
			$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
			$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
			$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
			$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
			$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
			$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
			$section	-> addTextBreak();				
		}
	} else {
		$asql = mysqli_query($splink,"Select B.CHNAME, B.CLASSCODE, B.CLASSNO, B.SCHHOUSE from APPLICATION_COMPETITION AS A inner join studentinfo AS B on A.STUID=B.STUID where A.COMPETITION_ID=\"".$row[5]."\" AND A.SCHYEAR=\"".$todayschyr."\" ORDER BY B.CLASSCODE, B.CLASSNO");
		$noofstud = mysqli_num_rows($asql);
		if ($noofstud > 0) {
			
				$tablename = "tabletrack".$row[3];	
				$$tablename = $section	->	addTable($contentTableStyle);
				$$tablename ->	addRow(200);
				$$tablename	->	addCell(900,array('valign' => 'center', 'borderColor' => '000000', 'borderTopSize' => 15,'borderBottomSize' => 15,'borderLeftSize' => 15,'borderRightSize' => 15))
								->	addText("項目(".$row[3].")",$font10,$paracenter);
				$$tablename ->	addCell(2100,array('gridSpan' => 2))
							->	addText("時間：".$row[6],$font10, $paracenter);
				$$tablename	->	addCell(3150,array('gridSpan' => 3,'valign' => 'center'))
								->	addText($row[0],$font10,$paracenter);
				$$tablename	->	addCell(2100,array('gridSpan' => 2, 'valign' => 'center'))
								->	addText($sex.$grade,$font10,$paracenter);
				$$tablename	->	addCell(1050,array('valign' => 'center', 'borderColor' => '000000', 'borderTopSize' => 15,'borderBottomSize' => 15,'borderLeftSize' => 15,'borderRightSize' => 15))
								->	addText($horf,$font10,$paracenter);
				$$tablename ->	addRow(400);
				$$tablename	->	addCell(900,$tracktabletitle) 	->	addText("組",$font10, $paracenter);
				$$tablename	->	addCell(1050,$tracktabletitle) 	->	addText("線道一",$font10, $paracenter);
				$$tablename	->	addCell(1050,$tracktabletitle) 	->	addText("線道二",$font10, $paracenter);
				$$tablename	->	addCell(1050,$tracktabletitle) 	->	addText("線道三",$font10, $paracenter);
				$$tablename	->	addCell(1050,$tracktabletitle) 	->	addText("線道四",$font10, $paracenter);
				$$tablename	->	addCell(1050,$tracktabletitle) 	->	addText("線道五",$font10, $paracenter);
				$$tablename	->	addCell(1050,$tracktabletitle) 	->	addText("線道六",$font10, $paracenter);
				$$tablename	->	addCell(1050,$tracktabletitle) 	->	addText("線道七",$font10, $paracenter);
				$$tablename	->	addCell(1050,$tracktabletitle) 	->	addText("線道八",$font10, $paracenter);
			
			$noofrow = floor($noofstud / 8) + 1;
			$x = 1;
			if ($x == $noofrow){
				$rowb = $borderbot20lef20;
				$rowp = $borderbot20lef10;
				$rowl = $borderbot20lef10rig20;
			} else {
				$rowb = $borderbot10lef20;
				$rowp = $borderbot10lef10;
				$rowl = $borderbot10lef10rig20;
			}
	
			$$tablename ->	addRow(400);
			$$tablename -> addCell(900,$rowb);
			$y = 1;
			while ($arow = mysqli_fetch_row($asql)){
				$celln = "cell".$row[5]."a".$x."b".$y;
				if ($y == 9) {
					$x++;
					if ($x == $noofrow){
						$rowb = $borderbot20lef20;
						$rowp = $borderbot20lef10;
						$rowl = $borderbot20lef10rig20;
					} else {
						$rowb = $borderbot10lef20;
						$rowp = $borderbot10lef10;
						$rowl = $borderbot10lef10rig20;
					}
					$$tablename -> addRow(400);
					$$tablename	->	addCell(900,$rowb);
					$y =1;
				}
				if ($y == 8 ){
					$$celln = $$tablename ->	addCell(1050,$rowl);
				} else {
					$$celln = $$tablename ->	addCell(1050,$rowp);
				}
	//			$textn = "text".$row[5]."a".$x."b".$y;
		//		$$textn = $$celln	-> addTextRun(array('alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER));
				$$celln ->	addText($arow[0],$font10,$paracenter);
				$$celln ->	addText($arow[1]."(".$arow[2].") ".$arow[3],$font10,$paracenter);
				$y++;
			}
			$leftc = 8 - $y +1;
			$tt = 0;
			while ($tt < $leftc ) {
				if ($tt == $leftc -1 ){
					$$tablename ->	addCell(1050,$rowl) ->	addText("",$font10);
				} else {
					$$tablename ->	addCell(1050,$rowp) ->	addText("".$leftc,$font10);
				}
				$tt++;
			}
			$$tablename ->	addRow(400);
			$$tablename	->	addCell(900, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
			$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
			$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
			$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
			$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
			$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
			$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
			$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
			$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
			$section	-> addTextBreak();				
		}
	}
}


//社際
$sql = mysqli_query($splink,"Select B.CH_DES, B.SEX, B.GRADE , A.ORDER_ID,A.HeatorFinal,A.COMPETITION_ID,A.EVENTTIME from COMPETITION_DATEID AS A inner join COMPETITIONITEM AS B ON A.COMPETITION_ID=B.keyid where A.DATE=\"".$endday."\" AND B.TRACKFIELD=\"1\" AND B.INTERHOUSE=\"1\" AND INTERCLASS=\"0\" ORDER BY A.ORDER_ID");
while ($row = mysqli_fetch_row($sql)){
	if ($row[4] == 0 ) {
		$horf = $txt1stheat;
	} else {
		$horf = $txtfinal;
	}
	if ($row[1] == 1) {
		$sex = $txtboy."子";
	} else if ( $row[1] == 2) {
		$sex = $txtgirl."子";
	} else {
		$sex = "";
	}
	if ($row[2] == "A"){
		$grade = $txtgradeA;
	} else if ($row[2] == "B" ) {
		$grade = $txtgradeB;
	} else if ($row[2] == "C" ){
		$grade = $txtgradeC;
	} else {
		$grade = "";
	}
	$tablename = "tabletrack".$row[3];	
	$$tablename = $section	->	addTable($contentTableStyle);
	$$tablename ->	addRow(200);
	$$tablename	->	addCell(900,array('valign' => 'center', 'borderColor' => '000000', 'borderTopSize' => 15,'borderBottomSize' => 15,'borderLeftSize' => 15,'borderRightSize' => 15))
					->	addText("項目(".$row[3].")",$font10,$paracenter);
	$$tablename ->	addCell(2100,array('gridSpan' => 2))
				->	addText("時間：".$row[6],$font10, $paracenter);
	$$tablename	->	addCell(3150,array('gridSpan' => 3,'valign' => 'center'))
					->	addText($row[0],$font10,$paracenter);
	$$tablename	->	addCell(2100,array('gridSpan' => 2, 'valign' => 'center'))
					->	addText($sex.$grade,$font10,$paracenter);
	$$tablename	->	addCell(1050,array('valign' => 'center', 'borderColor' => '000000', 'borderTopSize' => 15,'borderBottomSize' => 15,'borderLeftSize' => 15,'borderRightSize' => 15))
					->	addText($horf,$font10,$paracenter);
	$$tablename ->	addRow(400);
	$$tablename	->	addCell(900,$tracktabletitle) 	->	addText("組",$font10, $paracenter);
	$$tablename	->	addCell(1050,$tracktabletitle) 	->	addText("線道一",$font10, $paracenter);
	$$tablename	->	addCell(1050,$tracktabletitle) 	->	addText("線道二",$font10, $paracenter);
	$$tablename	->	addCell(1050,$tracktabletitle) 	->	addText("線道三",$font10, $paracenter);
	$$tablename	->	addCell(1050,$tracktabletitle) 	->	addText("線道四",$font10, $paracenter);
	$$tablename	->	addCell(1050,$tracktabletitle) 	->	addText("線道五",$font10, $paracenter);
	$$tablename	->	addCell(1050,$tracktabletitle) 	->	addText("線道六",$font10, $paracenter);
	$$tablename	->	addCell(1050,$tracktabletitle) 	->	addText("線道七",$font10, $paracenter);
	$$tablename	->	addCell(1050,$tracktabletitle) 	->	addText("線道八",$font10, $paracenter);

	$$tablename ->	addRow(400);
	$$tablename	->	addCell(900,$borderbot20lef20);
	$$tablename	->	addCell(1050,$borderbot20lef10) 	->	addText($txthouseRed."B",$font10, $paracenter);
	$$tablename	->	addCell(1050,$borderbot20lef10) 	->	addText($txthouseYellow."B",$font10, $paracenter);
	$$tablename	->	addCell(1050,$borderbot20lef10) 	->	addText($txthouseBlue."A",$font10, $paracenter);
	$$tablename	->	addCell(1050,$borderbot20lef10) 	->	addText($txthouseGreen."A",$font10, $paracenter);
	$$tablename	->	addCell(1050,$borderbot20lef10) 	->	addText($txthouseRed."A",$font10, $paracenter);
	$$tablename	->	addCell(1050,$borderbot20lef10) 	->	addText($txthouseYellow."A",$font10, $paracenter);
	$$tablename	->	addCell(1050,$borderbot20lef10) 	->	addText($txthouseBlue."B",$font10, $paracenter);
	$$tablename	->	addCell(1050,$borderbot20lef10rig20) 	->	addText($txthouseGreen."B",$font10, $paracenter);
	$$tablename ->	addRow(400);
	$$tablename	->	addCell(900, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
	$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
	$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
	$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
	$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
	$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
	$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
	$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
	$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
		
	$section	-> addTextBreak();				
}

//班際
$tablename = "tableclasss";	
$$tablename = $section	->	addTable($contentTableStyle);
$$tablename ->	addRow(200);
$$tablename	->	addCell(900,array('valign' => 'center', 'borderColor' => '000000', 'borderTopSize' => 15,'borderBottomSize' => 15,'borderLeftSize' => 15,'borderRightSize' => 15))
				->	addText("項目(XX)",$font10,$paracenter);
$$tablename ->	addCell(2100,array('gridSpan' => 2))
			->	addText("時間：XXXX",$font10, $paracenter);
$$tablename	->	addCell(3150,array('gridSpan' => 3,'valign' => 'center'))
				->	addText("班際接力比賽",$font10,$paracenter);
$$tablename	->	addCell(2100,array('gridSpan' => 2, 'valign' => 'center'));
$$tablename	->	addCell(1050,array('valign' => 'center', 'borderColor' => '000000', 'borderTopSize' => 15,'borderBottomSize' => 15,'borderLeftSize' => 15,'borderRightSize' => 15))
				->	addText("決骞",$font10,$paracenter);
$$tablename ->	addRow(400);
$$tablename	->	addCell(900,$tracktabletitle) 	->	addText("組",$font10, $paracenter);
$$tablename	->	addCell(1050,$tracktabletitle) 	->	addText("線道一",$font10, $paracenter);
$$tablename	->	addCell(1050,$tracktabletitle) 	->	addText("線道二",$font10, $paracenter);
$$tablename	->	addCell(1050,$tracktabletitle) 	->	addText("線道三",$font10, $paracenter);
$$tablename	->	addCell(1050,$tracktabletitle) 	->	addText("線道四",$font10, $paracenter);
$$tablename	->	addCell(1050,$tracktabletitle) 	->	addText("線道五",$font10, $paracenter);
$$tablename	->	addCell(1050,$tracktabletitle) 	->	addText("線道六",$font10, $paracenter);
$$tablename	->	addCell(1050,$tracktabletitle) 	->	addText("線道七",$font10, $paracenter);
$$tablename	->	addCell(1050,$tracktabletitle) 	->	addText("線道八",$font10, $paracenter);

$x = 1;
while ($x < 7) {
	if ($x == 6) {
		$rowb = $borderbot20lef20;
		$rowp = $borderbot20lef10;
		$rowl = $borderbot20lef10rig20;
	} else {
		$rowb = $borderbot10lef20;
		$rowp = $borderbot10lef10;
		$rowl = $borderbot10lef10rig20;
	}
	$sql = mysqli_query($splink,"Select CLASSCODE from studentinfo where left(CLASSCODE,1) = \"".$x."\" GROUP BY CLASSCODE order by CLASSCODE");
	$startcol = floor (( 8 - mysqli_num_rows($sql)) /2);
	$$tablename ->	addRow(400);
	$$tablename	->	addCell(900,$rowb) 	->	addText($x,$font10,$paracenter);
	$t = 0;
	while ($t < $startcol) {
		$$tablename	->	addCell(1050,$rowp);
		$t++;
	}
	while ($row = mysqli_fetch_row($sql)){
		$$tablename	->	addCell(1050,$rowp) 	->	addText($row[0],$font10, $paracenter);
		$t++;
	}
	while ($t < 8) {
		if ($t == 7) {
			$$tablename	->	addCell(1050,$rowl);
		} else {
			$$tablename	->	addCell(1050,$rowp);
		}
		$t++;
	}
	$x++;
}
$$tablename ->	addRow(400);
$$tablename	->	addCell(900, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
$section	-> addTextBreak();				

//校友師生學會接力
$tablename = "tableclub";	
$$tablename = $section	->	addTable($contentTableStyle);
$$tablename ->	addRow(200);
$$tablename	->	addCell(900,array('valign' => 'center', 'borderColor' => '000000', 'borderTopSize' => 15,'borderBottomSize' => 15,'borderLeftSize' => 15,'borderRightSize' => 15))
				->	addText("項目(XX)",$font10,$paracenter);
$$tablename ->	addCell(2100,array('gridSpan' => 2))
			->	addText("時間：XXXX",$font10, $paracenter);
$$tablename	->	addCell(3150,array('gridSpan' => 3,'valign' => 'center'))
				->	addText("校友師生學會接力",$font10,$paracenter);
$$tablename	->	addCell(2100,array('gridSpan' => 2, 'valign' => 'center'));
$$tablename	->	addCell(1050,array('valign' => 'center', 'borderColor' => '000000', 'borderTopSize' => 15,'borderBottomSize' => 15,'borderLeftSize' => 15,'borderRightSize' => 15))
				->	addText("決賽",$font10,$paracenter);
$$tablename ->	addRow(400);
$$tablename	->	addCell(900,$tracktabletitle) 	->	addText("組",$font10, $paracenter);
$$tablename	->	addCell(1050,$tracktabletitle) 	->	addText("線道一",$font10, $paracenter);
$$tablename	->	addCell(1050,$tracktabletitle) 	->	addText("線道二",$font10, $paracenter);
$$tablename	->	addCell(1050,$tracktabletitle) 	->	addText("線道三",$font10, $paracenter);
$$tablename	->	addCell(1050,$tracktabletitle) 	->	addText("線道四",$font10, $paracenter);
$$tablename	->	addCell(1050,$tracktabletitle) 	->	addText("線道五",$font10, $paracenter);
$$tablename	->	addCell(1050,$tracktabletitle) 	->	addText("線道六",$font10, $paracenter);
$$tablename	->	addCell(1050,$tracktabletitle) 	->	addText("線道七",$font10, $paracenter);
$$tablename	->	addCell(1050,$tracktabletitle) 	->	addText("線道八",$font10, $paracenter);

$$tablename ->	addRow(400);
$$tablename	->	addCell(900,$borderbot20lef20);
$$tablename	->	addCell(1050,$borderbot20lef10);
$$tablename	->	addCell(1050,$borderbot20lef10);
$$tablename	->	addCell(1050,$borderbot20lef10);
$$tablename	->	addCell(1050,$borderbot20lef10);
$$tablename	->	addCell(1050,$borderbot20lef10);
$$tablename	->	addCell(1050,$borderbot20lef10);
$$tablename	->	addCell(1050,$borderbot20lef10);
$$tablename	->	addCell(1050,$borderbot20lef10rig20);


$$tablename ->	addRow(400);
$$tablename	->	addCell(900, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
$$tablename	->	addCell(1050, array('borderColor' => '000000', 'borderTopSize' => 20)) ;
$section	-> addTextBreak();				

$section	->	addPageBreak();

$section	->	addTextBreak();
$section	->	addText("鳴謝",$bold48,$paracenter);
$section	->	addText($company.$sportdayname."得以順利進行，端賴各界人士熱心支持匡助，謹誌芳名，以表謝忱。",$font18,$thankslinespace);
$section	->	addText("一、　XXXX蒞臨頒獎及致訓。",$font18,$thankslinespace);
$section	->	addText("二、　各位嘉賓出席支持本校".$sportdayname,$font18,$thankslinespace);
$section	->	addText("三、　校監贊助教職員午膳。",$font18,$thankslinespace);
$section	->	addText("四、　康樂及文化事務署借出運動場地及提供服務。",$font18,$thankslinespace);
$section	->	addText("五、　元朗大球場員工鼎力協助。",$font18,$thankslinespace);
$section	->	addText("六、　醫療輔助隊協助救傷工作。",$font18,$thankslinespace);


//平面圖
$section ->	addPageBreak();
$section->addImage('img/locationmap.jpg',array('alignment'=>'center','height'=>900));


// Saving the document as OOXML file...
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');

	$filename = "eventbook.docx";
	header("Cache-Control: no-cache");
	header('Expires: 0');
	header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
	header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document;'); //mime type
	header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
	header('Content-Description: File Transfer');
	header('Content-Transfer-Encoding: binary');


	$objWriter ->save('php://output');		
}
//finish download eventbook



