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 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化