搜尋

首頁  >  問答  >  主體

將限制只顯示學生 ID 為 # 1,不包括其他一切內容

<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.2rd_Grading, t1.Status, SUM(t1.1st_Grading t1.2rd_Grading, t1.31. 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粉807239416P粉807239416551 天前398

全部回覆(1)我來回復

  • P粉415632319

    P粉4156323192023-08-08 19:31:32

    當使用者點擊學生 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";

    回覆
    0
  • 取消回覆