简体   繁体   English

如何添加链接以编辑和删除使用 php 制定的表中的每一行

[英]How to add a link to edit and delete each row in a table formulated using php

I have written php code that outputs a php table and for each row, I want to be able to add an extra column to an edit and delete link (CRUD functionality).我已经编写了输出 php 表的 php 代码,对于每一行,我希望能够在编辑和删除链接中添加一个额外的列(CRUD 功能)。 Currently I have been able to add the extra column but I am unsure on how to actually add the edit and update links in each row.目前我已经能够添加额外的列,但我不确定如何在每一行中实际添加编辑和更新链接。 My table currently looks like this.我的桌子目前看起来像这样。 [1]: https://i.stack.imgur.com/nwFzQ.png [1]: https://i.stack.imgur.com/nwFzQ.png

The table is made using html code and the data is received using php code that is linked to another file.该表是使用 html 代码制作的,并且使用链接到另一个文件的 php 代码接收数据。 The following is the html code,以下是html代码,

      <table class="content-table">
    <thead>
        <tr>
          <th>Cashflow</th>
          <th>Amount</th>
          <th>Description</th>
          <th colspan="2">Action</th>
        </tr>
      </thead>
      <tbody>
        <?php include_once('data.php'); ?>

      </tbody>
  </table>

The following is the php code (data.php):以下是php代码(data.php):

      while ($data = mysqli_fetch_assoc($output)) {
    echo "<tr><td>". $data["cashflow"] ."</td><td>". $data["amount"] ."</td><td>". $data["description"] ;
  }

You need some ID from database example: $data["id"]您需要数据库示例中的一些 ID:$data["id"]

    while ($data = mysqli_fetch_assoc($output)) {
    echo "<tr>";
    echo "<td>". $data["cashflow"] ."</td>";
    echo "<td>". $data["amount"] ."</td>";
    echo "<td>". $data["description"]."</td>";
    echo '<td><a href="URL TO EDIT?id='.$data["id"].'">Edit</a></td>';
  }

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

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