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 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了