douci7521 2015-08-28 05:32
浏览 31
已采纳

Wordpress删除表中的行

I'm making an admin plugin on my wordpress site. Im trying to add some delete function on my table row. my table is inside a foreach loop

 $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'/>";
        }   

and here's my code for delete

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 ));

this code is not working when I click the delete button, its only redirecting on my admin page like nothing happened.

  • 写回答

1条回答 默认 最新

  • dopzc64662 2015-08-28 06:19
    关注

    Try This.

    Change

     echo "<tr><form class='form' action='' method='post'>";
    

    TO

    echo "<tr><form class='form' action='get_permalink()?page=page_slug' method='post'>";
    

    Secord Code paregraph Add.

    global $wpdb;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了
  • ¥100 H5网页如何调用微信扫一扫功能?