如何从数据库中检索ID以进行信息删除


how is common to retrieve id from database for information deletion

我正在尝试使用post方法从数据库中删除一些数据,但我无法决定如何检索元素的id以完成标记的操作。 这是PHP脚本=>

<?php
echo "<form action='index.php' name='del_file_f' id='del_file_f' method='post'>";
                            echo "<table>";
                                for ($i=0;$i<$get_r->num_rows;$i++){
                                    $get_row = $get_r->fetch_assoc();
                                    echo "<tr>";
                                        echo "<td><p>" . $get_row['f_title'] . "." . $get_row['file_ext'] . "</p></td>";
                                        echo "<td><a href='" . $config->host . "/" . constant("FILE_PLACE") . "/" . $get_row['doc_folder'] . "/" . $get_row['doc_name'] . "." . $get_row['file_ext'] . "'><div class='img_down'></div></a><input type='hidden' name='del_file_" . $i . "' value='" . $get_row['id'] . "'><a href='javascript: void(0)' class='alink' id='" . $i . "'><div class='img_del'></div></a></td>";
                                        echo "<td><p>" . $get_row['f_size'] . "</p></td>";
                                    echo "</tr>";
                                }
                            echo "</table>";
                        echo "</form>";
?>

并且我正在尝试在隐藏元素中进行操作,由于行数,该元素的名称未知,我只需要知道这个名称即可完成此任务,任何想法如何获取此名称的信息? 或者如何获取每行已知的$get_row['id'](它是 mysql 数据库中行的 id)? 谢谢

更新

更简单的是,当从数据库中检索数据时,它将看起来像这样=>

文件名 | 下载 |文件大小 |删除图像 |

一 | 一些链接 | 2MB | 锚 |

我只是希望能够从这个选择中删除所需的数据,为此我需要知道隐藏元素的id,它的名字也是未知的。如果我设置隐藏元素名称来修复名称,它将覆盖其他元素。

更改

echo "<td><a href='" . $config->host . "/" . constant("FILE_PLACE") . "/" . $get_row['doc_folder'] . "/" . $get_row['doc_name'] . "." . $get_row['file_ext'] . "'><div class='img_down'></div></a><input type='hidden' name='del_file_" . $i . "' value='" . $get_row['id'] . "'><a href='javascript: void(0)' class='alink' id='" . $i . "'><div class='img_del'></div></a></td>";

echo "<td><a href='" . $config->host . "/" . constant("FILE_PLACE") . "/" . $get_row['doc_folder'] . "/" . $get_row['doc_name'] . "." . $get_row['file_ext'] . "'><div class='img_down'></div></a><input type='hidden' name='del_file[]' value='" . $get_row['id'] . "'><a href='javascript: void(0)' class='alink' id='" . $i . "'><div class='img_del'></div></a></td>";

然后,您将有一个带有每个键的 post 数组 $_POST['del_file'],然后您可以使用 foreach 进行循环,如下所示:

foreach($_POST['del_file'] as $i){
//delete mysql using $i as the row id
}