admin管理员组文章数量:1128472
I am having trouble finding a good resource on using the $wpdb function.
I am trying to delete a row from a custom table named: eLearning_progress
$removefromdb = $wpdb->query("DELETE FROM eLearning_progress WHERE ID = '$user_id' AND module_id = '$singlecomparearrays_remove'" );
The row I would like to delete has the ID of '$user_id' and the 'module_id' of '$singlecomparearrays_remove'.
I have also tried:
$removefromdb = $wpdb->query( "DELETE FROM eLearning_progress WHERE ID = ($user_id) AND module_id = ($singlecomparearrays_remove)" );
and then:
$removefromdb = $wpdb->query($wpdb->prepare("DELETE FROM eLearning_progress WHERE ID = %s AND module_id = %s", $user_id, $singlecomparearrays_remove));
Please try not to sigh too loudly at my attempts but I can't find a good guide on using the DELETE command with variables in there too. Any help is much appreciated.
Regards, Alex
I am having trouble finding a good resource on using the $wpdb function.
I am trying to delete a row from a custom table named: eLearning_progress
$removefromdb = $wpdb->query("DELETE FROM eLearning_progress WHERE ID = '$user_id' AND module_id = '$singlecomparearrays_remove'" );
The row I would like to delete has the ID of '$user_id' and the 'module_id' of '$singlecomparearrays_remove'.
I have also tried:
$removefromdb = $wpdb->query( "DELETE FROM eLearning_progress WHERE ID = ($user_id) AND module_id = ($singlecomparearrays_remove)" );
and then:
$removefromdb = $wpdb->query($wpdb->prepare("DELETE FROM eLearning_progress WHERE ID = %s AND module_id = %s", $user_id, $singlecomparearrays_remove));
Please try not to sigh too loudly at my attempts but I can't find a good guide on using the DELETE command with variables in there too. Any help is much appreciated.
Regards, Alex
Share Improve this question asked Jan 11, 2017 at 18:53 Alex GreenAlex Green 1111 gold badge1 silver badge5 bronze badges 2 |4 Answers
Reset to default 34The best WP API solution for this goal is to use the delete()
function to remove a row.
A small example, to delete the raw ID
in the custom table eLearning_progress
.
$id = 0815;
$table = 'eLearning_progress';
$wpdb->delete( $table, array( 'id' => $id ) );
But I can't see which raw you will delete in your table eLearning_progress
? Maybe you enhance the question to understand it much better.
It still possible that your sql is creating trouble even use $wpdb->delete
I found it useful using one of these approach:
- call
$wpdb->show_errors();
before querying - enable debug mode with
define( 'WP_DEBUG', true );
on your wp-config.php
Using This You can easily delete
$MailMetaKey = yourkey
$post_id = yourpostid
$wpdb->query($wpdb->prepare("DELETE * FROM f0_postmeta WHERE meta_key = $MailMetaKey' and post_id = '$post_id' "));
This code not working, show an error. I'm tried
Please look at this screenshot https://prnt.sc/M3DYH_EmHCtM
global $wpdb;
$id = $_REQUEST['delete'];
$table = 'custom_user_info';
$wpdb->delete( $table, array( 'id' => $id ) );
But when I'm using this code, It's working perfectly
$db_config = mysqli_connect('localhost', 'root', '', 'develop');
$id = $_REQUEST['delete'];
$delete = "DELETE FROM custom_user_info WHERE id=$id";
$query = mysqli_query($db_config, $delete);
本文标签: sqlHow to use wpdb to delete in a custom table
版权声明:本文标题:sql - How to use $wpdb to delete in a custom table 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736724270a1949642.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
delete()
? – bueltge Commented Jan 11, 2017 at 19:55