从php表行传递参数

时间:2017-03-26 21:29:06

标签: php html mysql sql phpmyadmin

是否可以通过php表中的一行通过href传递name_id参数?

Sample Code

<?php
    $name = $_GET["name"];
    $con = mysqli_connect("", "", "", "");
    if (mysqli_connect_errno()) {
        echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }

    $result = mysqli_query($con, "SELECT * FROM table WHERE name LIKE '%$name%' ");

    echo "<table class='table table-condensed'>
            <tr>
                <th> name id </th>
                <th> name </th>
                <th> link </th>
            </tr>";

    while ($row = mysqli_fetch_array($result)) {
        echo "<tr>";
            echo "<td>" . $row['name_id'] . "</td>";
            echo "<td>" . $row['name'] . "</td>";
            echo "<td>" . "<a href='name.php?name_id=$name_id'>view</a>" . "</td>";
        echo "</tr>";
    }
    echo "</table>";

    mysqli_close($con);
?>

EG。表中有多个带有自动递增id的名称,我希望它打开name.php页面,我可以从URL获取name_id吗?

提前致谢。

2 个答案:

答案 0 :(得分:0)

我认为这将是最简单的解决方案

echo "<td>" . "<a href='name.php?name_id=" . $row['name_id'] . "'>view</a>" . "</td>";

答案 1 :(得分:0)

这对我有用。

{{1}}

希望这有助于某人!