I'm currently working on a Wordpress plugin, and ran into trouble when simple trying have a delete button for each of my rows..
My idea is like many others, that every single row has an ID, and when I click the button that belongs to that row - It should be deleted..
I also tried doing what this guy did...
https://stackoverflow.com/questions/20428783/delet-row-in-custom-wp-db#=
This is what I got:
<form action="" method="POST">
<table class="widefat">
<thead>
<tr>
<th>1</th>
<th>2</th>
<th>3</th>
<th>4</th>
<th>5</th>
</tr>
</thead>
<tbody>
<?php
global $wpdb;
$rows = $wpdb->get_results(
"
SELECT *
FROM skibInfo
WHERE skib_status = 'Forventet skib'
"
);
foreach ($rows as $row)
{
if(isset($_POST['deleteItem'])){
global $wpdb;
$table = $wpdb->prefix."skibInfo";
$skib_nr = $_POST['ID'];
$wpdb->delete( $table, array( 'ID' => $skib_nr), array( '%d' ));
}
echo "<tr>";
echo"<td>".$row->field1."</td>";
echo"<td>".$row->field2."</td>";
echo"<td>".$row->field3."</td>";
echo"<td>".$row->field4."</td>";
echo"<td>".$row->field5."</td>";
echo'<td><input type="submit" value="' . $row->ID . '" name="deleteItem" /></td>';
echo "</tr>";
}
?>
</tbody>
</table>
</form>