猿问

如何通过单击按钮更新一行数据

首先,我对 PHP 有点陌生。


我被要求更改一些代码并添加选项以查看字段的状态并标记已完成的行。所以我在我的 MySQL 数据库中添加了一个状态字段,它的标准值为 0。然后在按钮单击时我希望将其更改为值 1。基于此,我可以使用按钮投影交叉字形图标更新它,或投影一个复选标记,以便状态为“完成”。


现在我在更新部分遇到问题。我似乎无法通过单击按钮并仅更新该行来使其工作。如果有用,字段“prdh_num”是我的唯一值。


这是我使用的代码:


    function uren_error(){

    global $mysql;

    $sql = "

                SELECT * 

                FROM uren_error, medw

                WHERE uren_error.uren_datum between adddate(now(),-14) and now() AND medw.medw_num = uren_error.medw_num

                ORDER BY uren_error.prdh_num";

    $query = $mysql->query($sql);


    echo "<h1>Niet in MKG verwerkte uren van de afgelopen 14 dagen</h1>";

    echo "<div class='row' id='urenTabel'>";

    echo "<div class='col-xs-0 col-md-0'></div>";

    echo "<div class='col-xs-12 col-md-12'>";

    echo "<table class='table'>";

    echo "<thead>";

    echo "<th>Verwerkingsdatum</th>";

    echo "<th>Medewerker</th>";

    echo "<th>Productieorder</th>";

    echo "<th>Productieorder regel</th>";

    echo "<th>Bewerking</th>";

    echo "<th>Duur</th>";

    echo "<th>Status</th>";

    echo "<th>Actie</th>";

    echo "</thead>";

    while($row = mysqli_fetch_array($query)){


        $hours = floor($row['uren_tijd_man_std'] / 3600);

        $mins = floor($row['uren_tijd_man_std'] / 60 % 60);

        echo "<tr>";

        echo "<td>" .$row['uren_datum']. "</td>";

        echo "<td>" .$row['medw_roepnaam'] . " " . $row['medw_tussenvoegsel'] . " " . $row['medw_naam'] . "</td>";

        echo "<td>" .$row['prdh_num']. "</td>";

        echo "<td>" .$row['prdr_num']. "</td>";

        echo "<td>" .$row['bewerk_num']. "</td>";

        echo "<td>" .$hours.":".$mins. "</td>";


到目前为止我的更新代码:


$productieorder = $row['prdh_num'];

$updateStatus = "UPDATE uren_error SET uren_status = 1 WHERE prdh_num=".$productieorder."";

$query2 = $mysql->query($updateStatus);


RISEBY
浏览 208回答 2
2回答

慕丝7291255

以更简单的方式,您可以使用<a>标签来更新您的记录,而<form>不仅仅是附加您需要传递的参数。IE :echo "<td><a href='currentphppagename.php?prdh_num=".$row['prdh_num']."'></a></td>";并在同一页面上prdh_num使用$_GET,即:&nbsp;//check if have some value or not&nbsp; &nbsp; if (isset($_GET['prdh_num'])) {&nbsp; &nbsp; //getting value passed in url&nbsp; &nbsp; $productieorder =&nbsp; $_GET['prdh_num'];&nbsp; &nbsp; $updateStatus = "UPDATE uren_error SET uren_status = 1 WHERE prdh_num=".$productieorder."";&nbsp; &nbsp; $query2 = $mysql->query($updateStatus);&nbsp; &nbsp; }和其他使用方式,form您可以有一个隐藏字段并为其分配row值:echo "<td><form action='' method='POST'><input type='hidden' value=".$row['prdh_num']." name='prdh_num'/><input type='submit' name='submit'></input></form></td>";现在在submit同一页面上点击下面的检查://check if have some value or not&nbsp; &nbsp; if (isset($_POST['submit'])) {&nbsp; &nbsp; //getting value passed in url&nbsp; &nbsp; $productieorder =&nbsp; $_POST['prdh_num'];&nbsp; &nbsp; $updateStatus = "UPDATE uren_error SET uren_status = 1 WHERE prdh_num=".$productieorder."";&nbsp; &nbsp; $query2 = $mysql->query($updateStatus);&nbsp; &nbsp; }

交互式爱情

你可以用 javascript 做到这一点。您应该在 tr 标签上放置“ondblclick”事件。<tr ondblclick="Update(rowno)" />而在 javascript 标签中,必须有一个类似的功能&nbsp; &nbsp; <script type="text/javascript">&nbsp; &nbsp; &nbsp; &nbsp; function Uptdate(row) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; window.location.href ="update.php?row="+row;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; </script>
随时随地看视频慕课网APP
我要回答