从php中的选定行获取列的值

时间:2018-02-20 03:16:47

标签: php sql

我是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的值?

1 个答案:

答案 0 :(得分:1)

如果你需要带有锚标签的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

相关问题