繁体   English   中英

表格每行上的 PHP 按钮

[英]PHP Button on each row of table

我正在用 PHP 制作一些申请表。

我将从数据库返回的所有信息放入一个表中。

现在我想在每一行上创建一个按钮,该按钮会更改该行的 DB 中的某些内容。

但我不知道这样做:S

谢谢!

echo "<table border='1'>
<tr>
<th>Id</th>
<th>Name</th>
<th>Email</th>
<th>age</th>
<th>position</th>
<th>experience</th>
<th>motivation</th>
<th>date</th>
<th>status</th>
<th>test</th>
</tr>";

while($row = mysql_fetch_array($result))
    {
        echo "<tr>";
    echo "<td>" . $row['id'] . "</td>";
    echo "<td>" . $row['name'] . "</td>";
    echo "<td>" . $row['email'] . "</td>";
    echo "<td>" . $row['age'] . "</td>";
    echo "<td>" . $row['position'] . "</td>";
    echo "<td>" . $row['exp'] . "</td>";
    echo "<td>" . $row['motivation'] . "</td>";
    echo "<td>" . $row['date'] . "</td>";
    echo "<td>" . $row['status'] . "</td>";
    echo "<td>" . '<input type="submit" name="submit" value="accept">' . "</td>";
    echo "</tr>";

}
    echo "</table>";

编辑:使用另一个脚本让它工作:

echo "<td><a href=\"edit.php?id=".$row['id']."&status=app\">Approve</a></td>";

和编辑.php:

<?php
include("dbconnect.php");
$member_id = $_GET['id'];
$status = $_GET['status'];
echo $member_id;
echo $status;
if ($status == 'app')
    $query = "update apps set status = 'approved' where id = $member_id";
mysql_query($query) or die (mysql_error());  
?>

在您希望按钮执行的单元格中创建带有参数的小型表单。 这是最简单的方法(刷新方法)。

另一种解决方案是在按钮单击和转发操作到某个端点时使用 AJAX。 这样它就会是动态的,并且可能是您想要实现的。

echo "<table border='1'>
<tr>
<th>Id</th>
<th>Name</th>
<th>Email</th>
<th>age</th>
<th>position</th>
<th>experience</th>
<th>motivation</th>
<th>date</th>
<th>status</th>
<th>test</th>
</tr>";

while($row = mysql_fetch_array($result))
    {
        echo "<tr>";
    echo "<td>" . $row['id'] . "</td>";
    echo "<td>" . $row['name'] . "</td>";
    echo "<td>" . $row['email'] . "</td>";
    echo "<td>" . $row['age'] . "</td>";
    echo "<td>" . $row['position'] . "</td>";
    echo "<td>" . $row['exp'] . "</td>";
    echo "<td>" . $row['motivation'] . "</td>";
    echo "<td>" . $row['date'] . "</td>";
    echo "<td>" . $row['status'] . "</td>";
    echo "<td>" . '<form type="POST"><input type="hidden" name="whatever" value="$row['id']"><input type="submit" name="submit_btn" value="accept"></form>' . "</td>";
    echo "</tr>";

}
    echo "</table>";

通过这种方式,您可以在表格的每一行中获得一个表格。 现在,您只需要使用 php POST 功能。

if(isset($_POST['submit_btn']))
{
//whatever u need to do
}

暂无
暂无

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

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