简体   繁体   English

表格每行上的 PHP 按钮

[英]PHP Button on each row of table

im making some application form in PHP.我正在用 PHP 制作一些申请表。

im putting all info returned from the database into a table.我将从数据库返回的所有信息放入一个表中。

Now i want to create a button on each line that changes something in the DB of that line.现在我想在每一行上创建一个按钮,该按钮会更改该行的 DB 中的某些内容。

but i have no idea to do that :S但我不知道这样做:S

Thank you!谢谢!

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>";

EDIT: get it working using another script:编辑:使用另一个脚本让它工作:

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

and edit.php:和编辑.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());  
?>

Create small form with parameters in the cell you want the button to do smth.在您希望按钮执行的单元格中创建带有参数的小型表单。 This is the simpliest approach (approach with refresh).这是最简单的方法(刷新方法)。

One more solution is to use AJAX on button click and forward action to some endpoint.另一种解决方案是在按钮单击和转发操作到某个端点时使用 AJAX。 This way it would be dynamic and probably what you are want to implement.这样它就会是动态的,并且可能是您想要实现的。

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>";

in this way, you could get a form in each row of the table.通过这种方式,您可以在表格的每一行中获得一个表格。 Now, you just need to use php POST function.现在,您只需要使用 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