search

Home  >  Q&A  >  body text

Will limit display to student ID # 1 and exclude everything else

<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;">This is the result of this code, if you see the red arrow in the url, it is a student#1, which also includes student#2 items ![](https://i.stack.imgur.com/5wS7h.png)</pre> <p><br /></p>
P粉807239416P粉807239416545 days ago394

reply all(1)I'll reply

  • P粉415632319

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

    When the user clicks on the link with student ID 1, the parameter id in the link will be obtained, and then the global variable $_GET['id'] is used in PHP to query the database, and the WHERE clause is used in the query.

    // 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";

    reply
    0
  • Cancelreply