表格每行上的 PHP 按钮 [英] PHP Button on each row of table

查看:31
本文介绍了表格每行上的 PHP 按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

im making some application form in 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.

但我不知道这样做: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>";

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

get it working using another script:

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

和edit.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).

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

One more solution is to use AJAX on button click and forward action to some endpoint. This way it would be dynamic and probably what you are want to implement.

这篇关于表格每行上的 PHP 按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆