我现在正在进行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));
}
答案 0 :(得分:0)
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'
)
);
}