php - 找不到 Wordpress 插件 ID
问题描述
我目前有一个问题,我无法从我的 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
解决方案
您fc_adherents
在选择查询中使用表名,但adherents
在删除中使用。
您需要更改表名或前缀。
您的选择查询表
global $wpdb;
$adherent_table_name = $wpdb->prefix . 'fc_adherents';
你的删除查询表
$table_name = $wpdb->prefix . 'adherents';
推荐阅读
- javascript - Rails:如何在点击时注入表单信息?
- amazon-web-services - Lambda 的 AWS 免费套餐定价
- java - 包不存在 - android/java
- python - 使用可变长度窗口大小的两列的滚动平均值
- ubuntu - 在 ubuntu 12.04 上安装错误 (95) cifs-utils
- c# - 使用表达式
> 在另一个表达式中 > - python - 如何使用 Python 内置函数成功处理大量 .txt 文件?
- javascript - 如何在没有可选查询字符串参数的情况下从 URL 获取路径或 slug
- powerbi - 如何在 Dax 中过滤 M2M 表
- react-native - 以下任务之间的循环依赖关系: :app:bundleReleaseJsAndAssets \--- :app:recordFilesBeforeBundleCommandRelease