dongshixingga7900 2016-05-13 00:03
浏览 69
已采纳

PHP - 获取单击表格行的ID

I'm currently creating the account management system of my website and I decided to add a feature that enables me to declare weather a specific account is active or inactive. The data is retrieved from my mysql table.

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

This is the content of 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");

What I need to do is get the ID of the row clicked and declare it in my session so that it can be used in the "status.php" file. But in this code, the last id in the table is the one that is declared into the session because of the loop. How do I get the value of the id of the row that is clicked? (is there sort of like onClick function in php? Thank you.

  • 写回答

4条回答 默认 最新

  • doumengmian1180 2016-05-13 00:10
    关注

    pass id parameter,

    status.php?id=$id;
    

    in status.php

    $id = $_GET['id'];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大