php 显示所有student_id # 1,不显示其他内容[关闭]

iqjalb3h  于 2023-08-02  发布在  PHP
关注(0)|答案(1)|浏览(96)

已关闭。此问题需要details or clarity。它目前不接受回答。
**希望改进此问题?**通过editing this post添加详细信息并阐明问题。

5小时前关闭
Improve this question
`` $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“;

Here's the result of this code and if you see the red arrow in url it's a student # 1 and inside it also includes student # 2 item

![](https://i.stack.imgur.com/5wS7h.png)

字符串

hxzsmxv2

hxzsmxv21#

当用户点击学生#1时,像这样在url中传递学生id ?id=1,并使用全局变量$_GET['id']在php中获取该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";

字符串

相关问题