簡體   English   中英

從php中的選定行獲取列的值

[英]Get the value of column from the selected row in php

我是 php 的初學者,我的導師給了我們一個任務。 如何獲取所選行中列的值?

<?php
  include 'connection.php';

    $sqlsearch = "SELECT `Student_ID`,`First_Name`,`Last_Name`,`Year_Level`,`Enrollment_Date`,`Status` FROM `student_info`";
    $sqlresult = $connection->query($sqlsearch);
    $searchInput = "";

    if($sqlresult->num_rows <= 0){
        echo "No found Result";
    }
    if(!empty($_GET["search"])){
        $searchInput = trim_input($_GET["search"]);

        $sqlsearch = "SELECT `Student_ID`,`First_Name`,`Last_Name`,`Year_Level`,`Enrollment_Date`,`Status` FROM `student_info`
                      WHERE `Student_ID` = '". $searchInput ."' OR `First_Name` LIKE '%". $searchInput ."%' OR `Last_Name` LIKE '%". $searchInput."%'";
        $sqlresult = $connection->query($sqlsearch);
            if($sqlresult->num_rows > 0){
              while($row = $sqlresult->fetch_assoc()){
                    generateResult($row);
              }
            }else{

            }
    }
    else{
      while($row = $sqlresult->fetch_assoc()){
         generateResult($row);
      }
    }


  function generateResult($row){
      echo "<tr>";
      echo '<td style="color:#33F0FF"> <a href="#">'. $row["Student_ID"] .'</a></td>'; //Plz get the student ID of the selected ID.
      echo '<td>'. $row["First_Name"] .'&nbsp'. $row["Last_Name"] .'</td>';
      echo '<td>'. $row["Year_Level"].'</td>';
      echo '<td>'. $row["Enrollment_Date"].'</td>';
        if($row["Status"] == "Active"){
          echo '<td style="color:green">'. $row["Status"].'</td>';
        }else if($row["Status"] == "Dropped"){
          echo '<td style="color:orange">'. $row["Status"].'</td>';
        }else{
          echo '<td style="color:red">'. $row["Status"].'</td>';
        }
      echo "</tr>";
  }
 ?>

在函數 generateResult($row) 中,單擊鏈接時如何獲取 Student_ID 的值?

如果您需要帶有錨標記的 student_id,您可能想通過單擊鏈接轉到其他頁面。 在這種情況下,替換:

echo '<td style="color:#33F0FF"> <a href="#">'. $row["Student_ID"] .'</a></td>';

echo '<td style="color:#33F0FF"> <a href="xyz.php?student_id=">'. $row["Student_ID"] .'</a></td>';

然后在 xyz.php 頁面上,您將使用$_GET["student_id"]獲取 student_id

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM