教学:项目十一网站设计比赛样题 – 模块四.docx
项目十一 网站设计比赛 样题-模块!U!样题-模块四模块简介: 世界技能组织想要从以前的比赛中分析和比较竞赛结果。他们有数据并且想要将分析的结果放到一个交互式的网站应用中去,以便于让有兴趣的浏览者能 从不同的角度去观察这些历年数据。 他们已经准备了一个非常基本的(静态)模板的接口。你的任务是实现服务器端的数据分析并结合模板生成页面。任务描述: 素材的XML档案中提供了原始数据,包含了例如职种编号,职种名称,国家,奖项,结果/总分,结果/每天分数(Dayl到Day4)等领域。有些数据仅仅 针对职种17 (网站设计项目)可用,或者针对某个特定的竞赛年度可用一一应当用这组数据作为本程序的一个样例。 用户应当能够按照所要求的筛选条件显示数据,效果应如如下草图:Medals by trade over the years113 - Autobody Repair |YearGoldSilverBronzeMedallion of Excellence2007BR - BrasilKR - Korea ID - IndonesiaCA - Canada2009?><! DOCTYPEhtmlPUBLIC"-/W3C/DTDXHTML1.0TransitionalEN”“http:><html xmlns二"http:www.w3.org/1999/xhtml”><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>WorldSkills Statistics</title></head><body><hl>WorldSkills Statistics</hl><div id="MedalsPerTrade"><h2>Medals by trade over the years</h2><form action="StatisticsTemplate.php" method="get" name="medals"><select name=,select"><option value="">Select a trade</option><?phpforeach ($Skills as $skill) list($numberz$nameEn)=$skill;$name= $number." - ".$nameEn;if ($number=$selectSkill) ?> <option value= <?php echo $number ?> selected="selected"x?php echo $name ?></option><?php else?><option value= <?php echo $number ?»<?php echo $name ?></option></select><button type="submit" name="showMedals" value="Show">Show</button></form><table border="l" align="left" summary="Select the trade with the dropdown above"><caption style="visibility:hidden">Medals by trade over the years</caption><thead><tr bgcolor="#CCCCCC"><th>Year</th><th>Gold</th><th>Silver</th><th>Bronze</th><th>Medaillon of Excellence</th></tr></thead><tbody><?phpforeach ($Results as $year=>$Rskill) ?><tr><td><?php echo $year ?></td><td><?phpforeach ($Rskill as $skillKey=>$medalArrVal)foreach ($medalArrVal"GOLD" as $country)echo findContry($country);?><br/><?php ?></td><td><?phpforeach ($Rskill as $skillKey=>$medalArrVal)foreach ($medalArrVal as $medalArrVal)foreach (SmedalArrValC'SILVER" as $country)echo findContry($country);?><br/><?php ?></td><td><?phpforeach ($Rskill as $skillKey=>$medalArrVal)foreach ($medalArrVal as $medalArrVal)foreach ($medalArrVal"BRONZE" as $country)echo findContry($country);?><br/><?php ?></td><td><?phpforeach ($Rskill as $skillKey=>$medalArrVal)foreach ($medalArrVal"Medallion For Excellence" as $country)echo findContry($country);?><br/><?php ?></td></tr><?php ?></tbody></table></div><br clear="aH"><div id=,PerformancePerDay"><h2>Performance over the days</h2><form action="StatisticsTemplate.php" method="post" name=,performance"><select name=),selectl"><option value="">Select a trade</option><?phpforeach ($skillldArr as $skillid) foreach ($Skills as $skill)list($number;$nameEn)=$skill;if ($skillid=$number) $name= $number." - ".$nameEn;if ($skillid=$selectSkill_l)?><option value= "<?php echo $skillid ?>" selected="selected"x?php echo $name ?></option><?php else?><option value= "<?php echo $skillid ?>"><?php echo $name ?></option></select> <select name=,select2"><option value=H" selected>Select a competition/year</option><option value="2011">2011 - London</option><option value="2009" selected>2009 - Calgary</option><option value="”>-.</option></select><button type="submit" name="showPerformance" value=nShow">Show</button></form><img src="Competitorperformance.png" alt="Diagram shows the performance of the competitors over the four competition days - Select the trade and competition/year with the dropdown above" style="margin-top:10px"></div></body></html>排序:按年份Performance over the days 13 - Autobody Repair 200A - Calgary |t|AU - AustraliaCA- Canada» Average选手制作提示: 服务器端的框架或者库代码不可用,本模块中所有代码应该从零开始纯手工编写。 在那些没有特别规定的地方,你可以用表格的形式返回数据。如果对你有所帮助,你也能使用临时数据库表,但是对于所提供数据源的任何改变,均应当 在输出的图标/表格中展示出来。 文件命名:将所有文件保存在你的服务器根目录下,名为“ XX_Module_4",其中XX是你的机器编号 本模块要在2个小时内完成所指定的所有任务。参考代码:<?php/ /jjc 5C5C * 5jC 5C5C 5C 5jC 5C5C 5C 5C 5C 5C 5C 5C 5jC 5C 5C 5jC5C 5C 5C 5jC 5C 5C5C 5C读取Skill.txt文件建立Skills二维数组$Skills = array();$filename = "Skills.txt"$conts = file_get_contents($filename);$lines = explode(”n"5conts);foreach($lines as $line)$1 = exploded/,$line);array_push($Skills,$l);)按国家缩写查询全称function findContry($id)读取Countrys.txt文件建立Countrys二维数组$Countrys = array();$filename = "Countrys.txt"$conts = file_get_contents($filename);$lines = explode("n'$conts);foreach($lines as $line)$1 = explode(7,$line);array_push($Countrys,$l);foreach ($Countrys as $country_line) if ($country_line0=$id) $country_ret=$country_line0." - ".$country_linel;return $country_ret;读取Results.txt文件建立Resul组(技能为17的ts n维数) $selectSkill="17”;if(isset($_GET'select')$selectSkill = $_GET'select'$Results = array();$Results_skill=array();$Results_medal=array();$filename = "Results.txt"$conts = file_get_contents($filename);$lines = explode("n:$conts);foreach($lines as $line)$1 = explode(7,$line);$skill =$selectSkill;$countrylso = $l2;if (!array_key_exists($medal,$Results_medal)$Results_medal$medal = array();/$Results_medal$medal$year."_,.$skill."_".$countrylso=$countrylso;elseif($ll=$skill && !in_array($countrylso/$Results_medal)$Results_medal$medal$year."_".$skill.,_".$countrylso=$countrylso;/$Results_medal$medal$skill=$countrylso;)if (!array_key_exists($skill,$Results_skill)$Results_skill$skill = array();/$Results_skill$skill$medal= $Results_medal$medal;elseif (!in_array($Results_medal,$Results_skill)$Results_skill$skill$medal= $Results_medal$medal;)if (!array_key_exists($year,$Results)$Results$year = array();/$Results$year$skill=$Results_skill;清空$Results_medal=array();$Results_skill=array();elseif (!in_array($Results_skill,$Results)$Results$year$skill=$Results_skill;var_dump($Results_sk 川);读取 Performance.txt 文件建立 Performance 组$selectSkill_l=,17"if( $_POST)$selectSkilLl = $_POST'selectl'$selectYear="2009"if( $_POST)$selectYear = $_POST'select2'$Performance = array();$filename = "Performance.txt"$conts = file_get_contents($filename);$lines = explode("n"z$conts);$skillldArr=array。; 将 Skill 的 id 建立一个数组foreach($lines as $line)$1 = explode(',',$line);if ($selectYear=$lO && $selectSkill_l=$ll)if ($|2="AU")$PerformancerAU” 卜Array($l3,$l $Performance"CA,=Array($l3z$l4,$l5z$l6);if ($l2="Averagen)$Performance,Average,=Array($l3/$l4/$l5,$l6);)$sid=$ll;$skillldArr$sid=$ll;)/*var_dump($Performance);echo $Performance"AU"0.'<br>,;echo intval($Performance,AU"0)*400/30;echo "<br>"$a = intval($Performance"AU,l);echo $a;echo "<br>"echo intval($Rerformance"AU"l)*400/30;*/?><?php创建画布$im = imagecreatetruecolor(600,400);新建一个真彩色图像,默认背景是黑色,返回图像标 识符。另外还有一个函数imagecreate已经不推荐使用。imagefill($im/0,0Jmagecolorallocate($im/240,240,240);绘制所需要的图像$red = imagecolorallocate($im,255Q0);创建一个颜色,以供使用$green= imagecolorallocate($im,255,255,0);$blue= imagecolorallocate($im,23,14,139);$grey= imagecolorallocate($im,194,194,194);$blue= imagecolorallocate($im,0,255,0);$black = ImageColorAllocatefSim, 0,0,0);$white = lmageColorAllocate($im, 255,255,255);设定画线的宽度imagesetthickness($im,4);for ($i=0;$i<=6;$i+)$text=$i*5;$y=350-50*$i;画x轴imageline($im,50,$y,450,$y,$grey); 画一条直线imagettftext($im, 9, 0,30,$y, $black, “STXIH日$text);输出 y 轴坐标的数字文字 )画y轴imageline($im,50,360,50,50,$grey); 画一条直线$xx=50;for ($i=l;$i<5;$i+)$text="day".$i;echo $text;$xx=$xx+100;imageline($im,$xx,360,$xx,350,$grey); 画一短条直线imagettftext($im, 9, 0,$xx-80,370, $black, "STXIHEl.ttf", $text);/x 轴坐标的文字 )图表线条的解释文字imagettftext($im/10, 0,450,150, $red, "STXIHEl.ttf", "AU-Austrualia");imagettftext($im, 10, 0,450,200, $green, "STXIHEl.ttf","CA-Canada");imagettftext($im, 10, 0,450,250, $blue, "STXIHEl.ttf",HAverage");画AU的曲线$yl = 350-intval(intval($Performance"AU"0)*10);$y2 = 350-intval(intval($Performance"AU"l)*10);$y3 = 350-intval(intval($Performance"AU"2)*10);$y4 = 350-intval(intval($Performance"AU"3)*10);imageline($im,100,$yl,200,$y2,$red);imageline($im,200,$y2,300,$y3,$red);imageline($im,300,$y3/400,$y4/$red);画CA的曲线$yl = 350-intval(intval($Performance"CA"0)*10);$y2 = 350-intval(intval($Performance"CA"l)*10);$y3 = 350-intval(intval($Performance"CA"2)*10);$y4 = 350-intval(intval($Performance"CA"3)*10);imageline($im,100,$yl,200,$y2z$green);imageline($im,200,$y2,300,$y3,$green);imageline($im,300,$y3,400,$y4,$green);/ifflj Average 的曲线$yl = 350-intval(intval($Performance"Average"0)*10);$y2 = 350-intval(intval($Performance"AverageHl)*10);$y3 = 350-intval(intval($Performance"Average"2)*10);$y4 = 350-intval(intval($Performance"Average"3)*10);imageline($im,100,$yl,200,$y2,$blue);imageline($im,200,$y2,300,$y3,$blue);imageline($im,300,$y3,400,$y4,$blue);输出图像imagejpeg($im,"CompetitorPerformance.jpg");销毁图像,释放内存imagedestroy($im);