将限制只显示学生 ID 为 # 1,不包括其他一切内容
P粉807239416
P粉807239416 2023-08-07 21:06:11
0
1
397
<p>`` $query = "SELECT t1.ID,t1.student_id, t1.Subject, t1.1st_Grading, t1.2nd_Grading, t1.3rd_Grading, t1.4th_Grading, t1.Status, SUM(t1.1st_Grading + t1.2nd_Grading + t1.3rd_Grading + t1.4th_Grading) / 4 as Average FROM grading_system t1 LEFT JOIN studentdata t2 ON t1.student_Id = t2.ID GROUP BY t1.ID ";</p> <pre class="brush:php;toolbar:false;">这是这段代码的结果,如果你看到url中的红色箭头,它是一个学生# 1,里面还包括学生# 2项 ![](https://i.stack.imgur.com/5wS7h.png)</pre> <p><br /></p>
P粉807239416
P粉807239416

全部回复(1)
P粉415632319

当用户点击学生 ID 为 1 的链接时,将获取该链接中的参数 id,然后在 PHP 中使用 global 变量 $_GET['id'] 来查询数据库,并在查询中使用 WHERE 子句。

// Get the student ID from the URL parameter
$studentId = isset($_GET['id']) ? $_GET['id'] : null;


// Prepare the SQL query with the WHERE clause to fetch the specific student's data
$query = "SELECT t1.ID, t1.student_id, t1.Subject, t1.1st_Grading, t1.2nd_Grading, t1.3rd_Grading, t1.4th_Grading, t1.Status, 
          SUM(t1.1st_Grading + t1.2nd_Grading + t1.3rd_Grading + t1.4th_Grading) / 4 as Average 
          FROM grading_system t1 
          LEFT JOIN studentdata t2 ON t1.student_Id = t2.ID 
          WHERE t1.student_id = $studentId
          GROUP BY t1.ID";
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板