dongyuan7110 2015-09-14 20:52
浏览 45

Wordpress插件 - 只删除我点击的行?

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>
  • 写回答

1条回答 默认 最新

  • donglu2523 2015-09-14 23:11
    关注

    You're using the wrong $_POST value as the delete ID. You are checking for 'deleteItem' correctly, but you're using 'ID'. Change:

    $skib_nr = $_POST['ID'];
    

    to:

    $skib_nr = $_POST['deleteItem'];
    
    评论

报告相同问题?

悬赏问题

  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch