I am writing a WP-Plugin and now I would like to have a table view of the data in my DB and be able to delete an entry on Button-Click. So what I am trying to do:
--------------------------------------------
# 1 # Foo # Delete #
--------------------------------------------
# 2 # Boo # Delete #
--------------------------------------------
I am receiving all of my data from an sql-command executed via $wpdb
. This works perfectly fine (and creates the table as I wanted it to do. When the delete
Button/Text is pressed, I want the corresponding entry to be deleted (e.g. entry with name "Boo"). Sadly I have no idea how to access that special entry. I provided my code below. Does anyone know how I can access the element/data in the line where the corresponding "delete"-Button is? It would be great if I could define what arguments to pass in the "POST" of the table entries, since I can access the PK of the entry in my database.
<?php
include_once WP_CONTENT_DIR . '/DBService/DBInteractorService.php';
include_once WP_CONTENT_DIR . '/DBService/DBInteractionUtils.php';
class tp_clubView {
public $_tableData;
public $_dbInteractorService;
public $_tableHTML;
public function __construct() {
$this->init_process();
}
private function init_process() {
$this->$_dbInteractorService = DBInteractorService::getInstance();
$this->refreshTableData();
if (isset($_POST['dropEntry'])) {
echo($_POST['dropEntry'];
//what to do here?
}
}
private function refreshTableData() {
$mySQL= DBInteractionUtils::$_mySQL;
$this->$_tableData = $this->$_dbInteractorService->executeSelectStatement($mySQL);
$this->refreshTableEntries();
}
private function refreshTableEntries() {
$counter = 1;
$tableLayout = '<div>
<form name="form" action="' . $_SERVER['REQUEST_URI'] . '" method="post">
<table class="widefat myTable">
<thead>
<tr>
<th> Number </th>
<th> Name </th>
<th> Action </th>
</tr>
</thead>
';
$dataSet = $this->$_tableData;
foreach ($dataSet as $tableSet) {
$tableLayout = $tableLayout . '<tr>' .
'<td>' . $counter . '</td>' . '<td>' . $tableSet->name . '</td>' .
'<td><input type="hidden" name="dropEntry" value="' . $tableSet->id .'">' .
'<button type="submit">Delete</button>'
. '</input>' . '</tr>';
$counter = $counter + 1;
}
$tableEnd = '</table>
</form>
</div>';
$tableLayout = $tableLayout . $tableEnd;
$this->$tableHTML = $tableLayout;
}
public function createClubsTableDiv() {
return '<div value='. $this->$_tableHTML;
}
}
?>
Edit:
I could get data passed, sadly it is only the ID of the last entry passed (the last ID
inserted). Can I somehow save the current ID for each entry?