gpt4 book ai didi

wordpress - 如何使用查询更新 WordPress 数据

转载 作者:行者123 更新时间:2023-12-05 07:31:02 25 4
gpt4 key购买 nike

我现在正在做 BD 警察法考试,我想添加考试计数系统,但我的代码无法正常工作,我是 Mysql 初学者。

$charset_collate = $wpdb->get_charset_collate();
$variable211 = $wpdb->prefix . "exam_count";
$variable2111 = "CREATE TABLE IF NOT EXISTS $variable211 (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
countt DOUBLE NOT NULL
) $charset_collate;";
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta( $variable2111 );

这是我的代码:

$myrows1 = $wpdb->get_results( "SELECT * FROM $variable211 WHERE id=1" );
$count=$myrows1->countt;
$count=$count+1;
if(!$myrows1){
$sql1 = $wpdb->query( $wpdb->prepare( "INSERT INTO $variable211 ( countt) VALUES ( %f ) ",1));
}else{
$sql2= $wpdb->query( $wpdb->prepare( "UPDATE INTO SELECT * FROM $variable211 WHERE ID = 1 ( countt ) VALUES ( %f )",$count));
}

最佳答案

global $wpdb;
$myrows1 = $wpdb->get_results( "SELECT * FROM $variable211 WHERE id=1" );
$count=$myrows1->countt;
$count=$count+1;
if(!$myrows1){
$sql1 = $wpdb->insert(
$variable211,
array(
'countt' => '1'
),
array(
'%d'
)
);
}
else{
$sql2 = $wpdb->update(
$variable211,
array(
'countt' => $count
),
array(
'ID' => '1'
),
array(
'%d'
)
);
}

关于wordpress - 如何使用查询更新 WordPress 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51979214/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com