找不到Wordpress插件ID

时间:2018-06-26 09:22:26

标签: php wordpress

我目前遇到问题,无法从sql表中获取ID以删除行。

如果有人可以帮助我,请

    <?php

include plugin_dir_path( __FILE__ ).'\connection.php';
global $wpdb;
$adherent_table_name = $wpdb->prefix . 'fc_adherents';
$adherent_data = $wpdb->get_results("SELECT * FROM fc_adherents ORDER BY id_adherent ASC ");

foreach ($adherent_data as $data) { 
    echo '<tr>';
    echo '<th scope="row" class="check-column"><label class="screen-reader-text" for="cb-select-268">Sélectionner $data->prenom </label>
<input id="cb-select-268" type="checkbox" name="post[]" value="268">
<div class="locked-indicator">
<span class="locked-indicator-icon" aria-hidden="true"></span>
<span class="screen-reader-text">“f” est verrouillé</span>
</div></th>';
    $id=$table_ligne['id_adherents'];
    echo '<td/>';
    echo $data->nom;
    echo "</br><a href='http://lab-origami.local/wp-admin/admin.php?page=gestion+adherents%2Finclus%2Fmodif.php'id='$id&o=u'>Modifier</a></br>";
    echo "<input type='submit' name='supprimer' value='supprimer '>";
    echo '<td/>';
    echo $data->prenom;
    echo '<td/>';
    echo $data->courriel;
    echo '<td/>';
    echo $data->telephone;
    echo '<td/>';
    echo $data->date_adhesion;
    echo '<td/>';
    echo $data->types_abonnement;
    echo '<td/>';
    echo $data->types_d_adherents;
    echo '<td/>';
    echo $data->type_tarif;
    echo '<br/>';
    echo $data->id_adherent;
    echo '<tr/>';
}
?>
</table>
<h3 align="right"><?php echo count($adherent_data)?> éléments</h3>
<?php
    $table_name = $wpdb->prefix . 'adherents';
if(isset($_POST["supprimer"])){
global $wpdb;
     $wpdb->delete( $table_name, [ 'id_adherent' => $data->id_adherent] );
    }
?>

您可能已经注意到问题出在foreach每次返回时都会被删除的id

1 个答案:

答案 0 :(得分:0)

您在选择查询中使用表名fc_adherents,但在删除中使用adherents

您需要更改表名或前缀。

您选择的查询表

global $wpdb;
$adherent_table_name = $wpdb->prefix . 'fc_adherents';

您的删除查询表

$table_name = $wpdb->prefix . 'adherents';