简体   繁体   English

PHP GridView表,而行作为链接

[英]php GridView table while row as link

I've been searching about what i want and nothing.. If someone knows a tutorial or something like. 我一直在搜索我想要的东西,什么也没有。如果有人知道某个教程或类似的东西。

What i want is... 我想要的是...

I've a got table made in php... and i add a "link to get the id", 我有一个用php制作的表格...,我添加了“获取ID的链接”,

echo "<td><a href='profile.php?id=" . $row['id'] . "'>Details</a></td>";

using the ID from the transaction to show a full details from that ID. 使用交易中的ID来显示该ID的完整详细信息。 in the same page. 在同一页面上。

My question is... How can i show that id details... as a new table with that details.? 我的问题是...我如何显示该ID详细信息...作为具有该详细信息的新表格?

You need to add condition in your file with that table (I am assuming it is the profile.php file). 您需要使用该表在文件中添加条件(我假设它是profile.php文件)。

If your code looks something like this: 如果您的代码如下所示:

$mysqli = new mysqli("localhost", "user", "password", "database");

$result = $mysqli->query("SELECT * FROM users");

while ($row = $result->fetch_assoc()) {
        echo "<table>";
        echo "<tr>";
        ...
        echo "<td><a href='profile.php?id=" . $row['id'] . "'>Details</a></td>";
        ...
        echo "</tr>";
        echo "</table>";
}

Just change it this way: 只是这样改变它:

$mysqli = new mysqli("localhost", "user", "password", "database");

if (!empty($_GET['id'])) {
        $id = $mysqli->real_escape_string($_GET['id']);
        $result = $mysqli->query("SELECT * FROM users WHERE id=".$id);

        $row = $result->fetch_assoc();
        echo "User data: <br>";
        echo "Name: ".$row['name']."<br>";
        ...
} else {
        $result = $mysqli->query("SELECT * FROM users");

        while ($row = $result->fetch_assoc()) {
                echo "<table>";
                echo "<tr>";
                ...
                echo "<td><a href='profile.php?id=" . $row['id'] . "'>Details</a></td>";
                ...
                echo "</tr>";
                echo "</table>";
        }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM