我正在我的wordpress网站上制作管理员插件。我试图在我的表行添加一些删除功能。我的桌子在foreach循环中
$edteams = $wpdb->get_results(" //some sql query ");
foreach ($edteams as $row) {
echo "<tr><form class='form' action='' method='post'>";
echo "<td>$row->team_id</td>";
echo "<td>$row->team_name</td>";
echo "<td><input class='input' type='text' name='won' value='$row->games_won'> </td>";
echo "<td><input class='input' type='text' name='lost' value='$row->games_lost'> </td>";
echo "<td><input class='input' type='text' name='pct' value='$row->game_pct'></td>";
echo "<td><input class='input' type='text' name='streak' value='$row->winning_streak'></td>";
echo "<td><button class='btn btn-default' name='update'><span class='glyphicon glyphicon glyphicon-edit'></span></button>
<button class='btn btn-default' name='delete' value='$row->team_id'><span class='glyphicon glyphicon-trash'></span></button></td>";
echo "</tr>";
echo "<input type='hidden' id='team_id' value='$row->team_id'/>";
}
这是我的删除代码
if(isset($_POST['delete']))
{
echo "<script>alert('Your account is now deleted'); </script>";
$id = $wpdb->get_results("SELECT a.team_id, a.team_name, a.program_id ,b.games_won, b.games_lost, b.game_pct, b.winning_streak
FROM program_teams as a
INNER JOIN program_team_standings as b
ON a.team_id=b.team_id");
foreach ($id as $row) {
echo $id = $row->team_id;
}
echo "<script>alert('Your account is now deleted'); </script>";
$wpdb->delete( 'program_teams', array( 'team_id' => $id ) );
$wpdb->delete( 'program_team_standings', array( 'team_id' => $id ));
当我单击删除按钮时,此代码无法正常工作,它只在我的管理页面上重定向,就像什么都没发生一样。
答案 0 :(得分:0)
试试这个。
更改强>
echo "<tr><form class='form' action='' method='post'>";
以强>
echo "<tr><form class='form' action='get_permalink()?page=page_slug' method='post'>";
Secord Code paregraph Add。
global $wpdb;