如何在HTML表的每一行上添加编辑按钮

时间:2016-09-14 04:44:41

标签: javascript php html css

(就是这样。我不知道如何在每行的“编辑列”下添加编辑按钮。)   请建议我解决这个问题。

enter link description here
http://localhost/test/logindetails.php?edit=Modify#
enter code here

<?php
// making connection

$conn=mysqli_connect('localhost','root','') ;

// selecting database

    mysqli_select_db($conn,"company") ;
    $sql= "SELECT * FROM login" ;
    $records=mysqli_query($conn,$sql) ;
?> 
<html>
    <head>
        </script>
        <title>Details!!!!</title>
    </head>
    <body>
        &#9824;
        <h2>Details!!!!!!!!!</h2>
        <div>
            <table width="600" border="1" cellpadding="1" cellspacing="1">
                <tr>
                    <th>Id</th>
                    <th>Username</th>
                    <th>Password</th>
                    <th>Edit</th>
                </tr>
        </div>
    <?php
        while($std = mysqli_fetch_array($records)) 
        {
            echo "<tr>";
            echo "<td>" . $std['id'] . "</td>";
            echo "<td>" . $std['username'] . "</td>";
            echo "<td>" . $std['password'] . "</td>";
            echo "<td>" . $std['Edit'] . "</td>";
            echo "</tr>";
        }
    ?>
        </table>
    </body>
</html>

3 个答案:

答案 0 :(得分:1)

只是你想使用编辑链接创建mnew页面details.php重定向然后更新记录

while($std = mysqli_fetch_array($records)) 
{
    echo "<tr>";

    echo "<td>" . $std['id'] . "</td>";

    echo "<td>" . $std['username'] . "</td>";

    echo "<td>" . $std['password'] . "</td>";

    echo "<td><a href='details.php?id=".$std['id']."'>Edit</a></td>";

    echo "</tr>";

}

答案 1 :(得分:0)

如果没有数据库连接,请使用:

<table>
<tbody>
<?php for($i=0;$i<11;$i++){?>
<tr><td><input type="submit" value="submit"/></td></tr>
<?php } ?>
</table>

它将打印一个包含10行的表格,并且所有td都包含一个按钮。

答案 2 :(得分:0)

    $str = "select * from mytable";
    $sql = mysqli_query($str );

    <table>
    <?php while($data = mysqli_fetch_array($sql)){ ?>
        <tr>
             <td><? echo $data; ?></td>
             <td><button>or anything to edit</button></td>
        </tr>
    <?php } ?>
    </table>

它将打印与数据库中的数据一样多。