Php 在一列中显示多个数据
我正在制作一个显示成绩的网站 我的数据库中有3个表 第一个数据库是Php 在一列中显示多个数据,php,html,mysql,Php,Html,Mysql,我正在制作一个显示成绩的网站 我的数据库中有3个表 第一个数据库是master_list及其表 student_ID, firstname, middlename, lastname, birthday, age, sex, address, contacts, 第二张表:部分 student_section_id, school_year, Section_name, 第三张表:受试者 subject_id, subject_name, firstgrading
master_list
及其表
student_ID,
firstname,
middlename,
lastname,
birthday,
age,
sex,
address,
contacts,
第二张表:部分
student_section_id,
school_year,
Section_name,
第三张表:受试者
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
Filipino 4 90 91 88 89 90
这是这个问题所需的最小代码量吗?至少要努力将你的问题格式化,并使其可编辑。im new此处主题表不应具有重复列。示例:您正在使用的
mysql\uu
代码库已经过时。它在很久以前就被弃用了,然后在PHP7中被完全删除。众所周知,它是不安全的,不支持诸如预处理语句和参数化查询之类的东西,这大大降低了SQL注入攻击的风险。使用您现有的代码,您的数据很有可能被恶意用户或机器人攻击或破坏。切换到使用受支持的库(mysqli\uuu
或PDO
是选项),并习惯使用参数化的准备语句。你可以在网上找到很多例子。
Vince Monarca Carreon
Grade 10 2016 - 2017
English 4 80 84 83 82 82
Filipino 4 90 91 88 89 90