我正在建立一个显示成绩的网站。
我的数据库中有3个表。
第一个数据库是master_list
及其表
student_ID,
firstname,
middlename,
lastname,
birthday,
age,
sex,
address,
contacts,
第二张表:section
student_section_id,
school_year,
Section_name,
第三张表:subjects
subject_id,
subject_name,
firstgrading,
secondgrading,
thirdgrading,
fourthgrading,
average_grade,
remarks,
这是我的代码。
<?php
mysql_connect("localhost", "root", "") or die("Error connecting to database: ".mysql_error());
mysql_select_db("capstone") or die(mysql_error());
?>
<!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>
<title>Search results</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="style.css"/>
</head>
<body>
<?php
$query = $_GET['query'];
$min_length = 0;
if(strlen($query) >= $min_length){
$query = htmlspecialchars($query);
$query = mysql_real_escape_string($query);
$raw_results = mysql_query("SELECT firstname, middlename, lastname
,section_name, school_year
,subject_name, firstgrading, secondgrading, thirdgrading, fourthgrading, average_grade
FROM master_list,section,subjects
WHERE (student_id LIKE '".$query."')") or die(mysql_error());
if(mysql_num_rows($raw_results) > 0){
while($results = mysql_fetch_array($raw_results)){
echo "<p><h3>".$results['firstname']." ".$results['middlename']." ".$results['lastname']."</h3><br />"
.$results['section_name']." ".$results['school_year']."<br />"
.$results['subject_name']." ".$results['firstgrading']." ".$results['secondgrading']." ".$results['thirdgrading']." ".$results['fourthgrading']." ".$results['average_grade']."
</p>";
}
}
else{
echo "No results";
}
}
else{
echo "Minimum length is ".$min_length;
}?>
</body>
</html>
以下是结果:
Vince Monarca Carreon
Grade 10 2016 - 2017
English 4 80 84 83 82 82
Vince Monarca Carreon
Grade 10 2016 - 2017
Filipino 4 90 91 88 89 90
名称也循环,我想要的是名称不应该重复。喜欢这个
Vince Monarca Carreon
Grade 10 2016 - 2017
English 4 80 84 83 82 82
Filipino 4 90 91 88 89 90