码迷,mamicode.com
首页 > 其他好文 > 详细

班主任好帮手之统计学生成绩

时间:2015-04-27 09:58:15      阅读:121      评论:0      收藏:0      [点我收藏+]

标签:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>统计学生成绩</title>
</head>

<body>
  <?php
	$mydb = mysql_connect('localhost', 'root', '1234') or 
	die("Could not connect to database.");//连接数据库 
	mysql_query("set names 'utf8'");//输出中文 
	mysql_select_db("score_db", $mydb); 
	error_reporting(E_ALL ^ E_NOTICE); 
	
	$stuName = array();
	$n = 0; 
	$result = mysql_query("SELECT name FROM student_tb1  ORDER BY id");

	while($row = mysql_fetch_array($result))
	{
		$stuName[++$n] = $row['name'];
	}
	/*
	for ($i=1; $i<=$n; $i++)
	{
		echo $stuName[$i] . "<br/>";
	}
	*/
	$subName = array("时间","语文","语文平均","数学","数学平均","英语","英语平均","物理","物理平均","化学","化学平均","生物","生物平均","总分","阶段");
	$testTime  = array("中考", "一1期中","一2期中","一3期中"); 
	$ave = array(); //存储各科平均分
    $subject = array(); //存储各科成绩
	$count = array($subject); //存储各次考试各科成绩
	$stu = array($count); //存储每个学生各次考试各科成绩
	
	for ($i=1; $i<=$n; $i++)
	{
		for ($j=1; $j<=3; $j++)
		{
			$tb_name = 'student_tb' . $j;
			$result = mysql_query("SELECT * FROM  $tb_name  where name = '平均分'");
			while($row = mysql_fetch_array($result))
			{
				$ave[0] = $row['yuWen'];
				$ave[1] = $row['shuXue'];
				$ave[2] = $row['yingYu'];
				$ave[3] = $row['wuLi'];
				$ave[4] = $row['huaXue'];
				$ave[5] = $row['shengWu'];
			}
			$studentName = $stuName[$i];
			$result = mysql_query("SELECT * FROM  $tb_name  where name = '$studentName'");
			while($row = mysql_fetch_array($result))
			{
				$stu[$i][$j][0] = $row['yuWen'];
				$stu[$i][$j][1] = $ave[0];
				$stu[$i][$j][2] = $row['shuXue'];
				$stu[$i][$j][3] = $ave[1];
				$stu[$i][$j][4] = $row['yingYu'];
				$stu[$i][$j][5] = $ave[2];
				$stu[$i][$j][6] = $row['wuLi'];
				$stu[$i][$j][7] = $ave[3];
				$stu[$i][$j][8] = $row['huaXue'];
				$stu[$i][$j][9] = $ave[4];
				$stu[$i][$j][10] = $row['shengWu'];
				$stu[$i][$j][11] = $ave[5];
				$stu[$i][$j][12] = $row['zongFen'];
				$stu[$i][$j][13] = $row['duanMing'];
			}
		}
		
		echo "<hr />";
		echo $stuName[$i] . "<br/>";
		echo "<hr />";
		echo "<hr />";
		echo '<table width="900" border="1" cellpadding="0" cellspacing="0">';
	    echo '<tr>';
		for ($k=0; $k<15; $k++)
		{
			echo '<td>';
			echo $subName[$k];
			echo '</td>';
		}
		echo '</tr>';
		for ($j=1; $j<=3; $j++)
		{
			echo '<tr>';
			echo '<td>';
			echo $testTime[$j];
			echo '</td>';
			for ($k=0; $k<14; $k++)
			{
				echo '<td>';
				echo $stu[$i][$j][$k];
				echo '</td>';
			}
			echo '</tr>';
		}
		echo '</table>';
		echo '<br/>';
		echo '<br/>';
		echo '<br/>';
		echo '<br/>';
		echo '<br/>';
		echo "<br />";
		echo "<br />";
		echo "<br />";
		echo "<br />";
		echo "<br />";
		echo "<br />";
		echo "<br />";
		echo "<br />";
	}
	
	mysql_close($mydb);
  ?>
    
</body>
</html>

班主任好帮手之统计学生成绩

标签:

原文地址:http://blog.csdn.net/qiaoruozhuo/article/details/45292897

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!