[英]Get the value of column from the selected row in php
I'm a beginner in php and my instructor gave us a task.我是 php 的初学者,我的导师给了我们一个任务。 How can I get the value of the column in the selected row?
如何获取所选行中列的值?
<?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"] .' '. $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>";
}
?>
In the function generateResult($row) how can I get the value of Student_ID when I click the link?在函数 generateResult($row) 中,单击链接时如何获取 Student_ID 的值?
If you need student_id with anchor tag , probably you want to go to other page on clicking the link .如果您需要带有锚标记的 student_id,您可能想通过单击链接转到其他页面。 In that case , replace :
在这种情况下,替换:
echo '<td style="color:#33F0FF"> <a href="#">'. $row["Student_ID"] .'</a></td>';
to到
echo '<td style="color:#33F0FF"> <a href="xyz.php?student_id=">'. $row["Student_ID"] .'</a></td>';
Then on the xyz.php page , you will get student_id using $_GET["student_id"]
然后在 xyz.php 页面上,您将使用
$_GET["student_id"]
获取 student_id
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.