使用编辑按钮更新动态表

时间:2015-05-07 07:21:42

标签: php mysql

我已经拥有一个从数据库生成结果的动态表。

现在我想进行更新,它是如何工作的,当btn更新被点击时,表单应该允许用户从ID,案例,名称文档和日期更新信息......

我变得疯狂的问题是假设ID是我的PK而且它是$ ID如何在循环时设法获取特定行的$ ID?它也应该在同一个网页上,还是应该为更新编写另一个页面?

 ID|    Case|  Name| Document| Date       Edit
 ----------------------------------------------
 1     233    alex    ITR      2015-1-1   btn
 2     233    alex    ITR      2015-1-1   btn
 3     233    alex    NULL     0000-0-0
 4     234    ben     COC      2015-3-3
 5     234    ben     VAT      2015-3-3
 6     234    ben     NULL     0000-0-0

这是我的剧本:

$link = mysqli_connect("1xxxx","xxxx","xxxx","export_workflow") or die("Error " . mysqli_error($link)); 
     if($link->connect_errno){
          printf("Connect failed: %s\n", $mysqli->connect_error);
          exit();
     } 
     //consultation: 
     $query = "SELECT * FROM export_workflow.COLLATERAL_MANAGEMENT where ORIGINAL_DEADLINE > current_date;"; 
     //execute the query. 
     if($result = $link->query($query)){
           echo "<table class='table_style' id='table_example'>".
                "<thead>".
                "<tr>".
                "<td>App Number</td>".
                "<td>Spoc Assigned</td>".
                "<td>Borrower Name</td>".
                "<td>App Finish Date</td>".
                "<td>Developer & Project</td>".
                "<td>Collateral Address Details</td>".
                "<td>Deferred Document</td>".
                "<td>Deferred Type</td>".
                "<td>Original Deadline</td>".
                "<td>Date Completed</td>".
                "<td>SPOC Remarks</td>".
                "<td>File Location</td>".
                "<td>JUW MA Remarks</td>".
                "<td>COSU Remarks</td>".
                "<td>SMU Notes</td>".
                "<td> EDIT </td>".
                "</tr></thead>";

          while($row = $result->fetch_assoc()){

                echo "<tr><td>".$row['APP_NUMBER']."</td>".
                 "<td>".$row['SPOC_ASSIGNED']."</td>".
                 "<td>".$row['BORROWER_NAME']."</td>".
                 "<td>".$row['APP_FINISH_DATE']."</td>".
                 "<td>".$row['DEVELOPER_PROJECT']."</td>".
                 "<td>".$row['COLLATERAL_ADDRESS_DETAILS']."</td>".
                 "<td>".$row['DEFERRED_DOCUMENT']."</td>".
                 "<td>".$row['DEFERRED_TYPE']."</td>".
                 "<td>".$row['ORIGINAL_DEADLINE']."</td>".
                 "<td>".$row['DATE_COMPLETED']."</td>".
                 "<td>".$row['SPOC_REMARKS']."</td>".
                 "<td>".$row['FILED_LOCATION']."</td>".
                 "<td>".$row['JUW_MA_REMARKS']."</td>".
                 "<td>".$row['COSU_REMARKS']."</td>".
                 "<td>".$row['SMU_NOTES']."</td>".
                 "<td><a href='spoc_remarks.php'><image src='./images/pen.png' height=30 width=30></a></td>".
                 "</tr>";
          }
          $result->close();
          echo "</table>\r\n";
        } else {
          printf("<p>Error: %s</p>\r\n", $mysqli->error);
        }
        ?>

1 个答案:

答案 0 :(得分:0)

您可以将相关行ID传递到编辑页面。例如,

echo "<td><a href='edit.php?id=". $row['ID'] . "'> EDIT </a></td>";

然后在id页面中获取edit.php,在下一页上,您可以使用向doedit.php页面提交数据的表单。像这样的东西,

<form action="doedit.php" method="POST">
    <input type="hidden" name="ID" value="<?php echo $_GET['id']; ?>" >
    <input type="text" name="field1" >
    ....
    All other input fields.
    ...
</form>

doedit.php有更新查询来更新数据库中的数据。