表分析:
表一:学生信息表('studentInfo');
设计表时注意事项:1.性别(enum) 原因:我认为只有两种情况 '男' and '女' 2.年龄(date) 原因:人不是死的,每年都会长大,数据库年龄也得随之变大。
表二:学生分数表('studentScore');
具体实现功能:
1.添加 :学生本次考试情况添加多条,在这里设计到数组的处理:
仅供参考:
# 接收要添加的数据
$data = $_POST;
foreach($data as $k => $v){
foreach($v as $key => $val){
$data1[] = $val;
}
}
foreach($data1 as $value){
foreach($value as $kkk => $vvv){
$data2[$kkk][] = $vvv;
}
}
foreach($data2 as $vvvv){
if(empty($vvvv[2])){
unset($vvvv);
}else{
$sql = "insert into exam(stu_id,exam_score,exam_time)VALUES('".$vvvv[0]."','".$vvvv[1]."','".$vvvv[2]."')";
$result = mysqli_query($link,$sql);
}
}
2.列表展示
涉及到简单的数据处理,将学生的手机号隐藏中间四位(安全),还有对学生的详细信息及分数查询功能,邮箱发送功能,下面来看看我的列表展示吧。
数据详细介绍:(列表页默认展示学生的详细信息,如需查询学生得分情况,按照条件进行搜索,如果没有条件将会默认查询班级最近一次考试的得分情况)
下面是列表页条件及sql语句:
# 接收模糊查询的条件
$stuName = $_POST['stuName'];
$choose = $_POST['choose'];
$number = $_POST['number'];
# 按照学生名称查询
$where = 1;
if(!empty($stuName)){
$where .= " and stu_name like '%$stuName%'";
}
# 判断搜索的条件/类型
if($number){
if($choose == 0){
$where .= " and exam_score > '$number' order by exam_time desc";
}
if($choose == 1){
$where .= " and exam_score = '$number' order by exam_time desc";
}
if($choose == 2){
$where .= " and exam_score < '$number' order by exam_time desc";
}
}
# 根据条件查询查询数据 无条件将默认查询全部
if(!empty($where)){
$link = mysqli_connect('127.0.0.1','root','root','stu');
$sql = "select * from student join exam on student.stu_id=exam.stu_id where $where";
$result = mysqli_query($link,$sql);
$number = mysqli_num_rows($result);
if($number == 0){
echo 0;
}else{
while($arr = mysqli_fetch_assoc($result)){
$data['data'][] = $arr;
}
echo json_encode($data);
}
}