gpt4 book ai didi

PHP-获取单击的表行的 id

转载 作者:行者123 更新时间:2023-11-29 11:32:20 27 4
gpt4 key购买 nike

我目前正在为我的网站创建帐户管理系统,我决定添加一项功能,使我能够声明特定帐户是否处于事件状态。数据是从我的 mysql 表中检索的。

$query = mysqli_query($DBConnect,"SELECT * from REG");
echo "<table class = 'table' style = 'width:90%;text-align:center'>";
while($getData = mysqli_fetch_assoc($query))
{
$username = $getData['uname'];
$fname = $getData['fname'];
$mname = $getData['mname'];
$lname = $getData['lname'];
$bday = $getData['bday'];
$email = $getData['email'];
$contact = $getData['contact'];
$gender = $getData['gender'];
if($getData['userlevel'] == 1)
{
$userlevel = "user";
}
else
{
$userlevel = "admin";
}
if($getData['status'] == 1)
{
$status = "active";
}
else
{
$status = "disabled";
}

echo "<tr>";
echo "<td>$username</td><td>$fname</td><td>$mname</td><td>$lname</td><td>$bday</td><td>$email</td><td>$contact</td><td>$gender</td><td>$userlevel</td><td>
<a href ='..\status.php' >$status </a></td></tr>";

}
echo "</table>";

这是status.php的内容

session_start();
$DBConnect = mysqli_connect("localhost", "root","","kenginakalbo")
or die ("Unable to connect".mysqli_error());


$query = mysqli_query($DBConnect,"SELECT * from REG where id = '$_SESSION[id]'");
while($getData = mysqli_fetch_assoc($query))
{
$status = $getData['status'];
echo "'$_SESSION[id]'";
}

if($status == 1)
{
$query = mysqli_query($DBConnect, "UPDATE REG SET status = 0 where id = '$_SESSION[id]'");
}
else if ($status == 0)
{
$query = mysqli_query($DBConnect, "UPDATE REG SET status = 1 where id = '$_SESSION[id]'");
}

header("Location: admin/login.php");

我需要做的是获取单击的行的 ID 并在我的 session 中声明它,以便可以在“status.php”文件中使用它。但在此代码中,表中的最后一个 id 是由于循环而在 session 中声明的 id。如何获取单击的行的 id 值? (php中有类似onClick的函数吗?谢谢。

最佳答案

传递id参数,

status.php?id=$id;

status.php

$id = $_GET['id'];

关于PHP-获取单击的表行的 id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37199297/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com