我有一个页面显示在我的网站上通过paypal进行的所有交易。我想添加一个可以删除该特定行的按钮。
交易ID是唯一的。
当用户点击按钮删除该行时,我怎么能够?还运行jquery警报确认删除?
我的代码:
<table class"widefat">
<?php global $wpdb;
$result = $wpdb->get_results ( "SELECT * FROM wp_donations" );
if (!$result){?>
<tr>
<td>There are no donations to show</td>
</tr>
<?php }else{?>
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Phone Number</th>
<th>Address</th>
<th>Amount</th>
<th>Method</th>
<th>Date</th>
<th>Transaction ID</th>
<th></th>
</tr>
</thead>
<?php foreach ( $result as $print ) {?>
<tr>
<td><?php echo $print->name;?></td>
<td><?php echo $print->email;?></td>
<td><?php $phones = $print->phone; if($phones == 0){echo 'No Number Provided';}else{echo $phones;}?></td>
<td><?php echo $print->address;?></td>
<td>$<?php echo $print->amount;?></td>
<td><?php echo $print->method;?></td>
<td><?php echo $print->dates;?></td>
<td><?php echo $print->txid;?></td>
<td><input type="button" id="<?php echo $print->txid;?>" class="delete" title="Delete" value="delete" /></td>
</tr>
<?php }?>
</table>
答案 0 :(得分:2)
答案 1 :(得分:1)
我最终开始行动了。使用数据库中AUTO_INCREMENT
的唯一ID。
然后在页面加载时调用操作。
$actions = array(
'delete' => sprintf('<a href="?page=%s&action=delete&id=%s">%s</a>', $_REQUEST['page'], $item['id'], __('Delete', 'custom_table_example')),
);
function process_bulk_action()
{
global $wpdb;
$table_name = $wpdb->prefix . 'donations'; // do not forget about tables prefix
if ('delete' === $this->current_action()) {
$ids = isset($_REQUEST['id']) ? $_REQUEST['id'] : array();
if (is_array($ids)) $ids = implode(',', $ids);
if (!empty($ids)) {
$wpdb->query("DELETE FROM $table_name WHERE id IN($ids)");
}
}
}