此代码在从底部开始的第八行都能正常工作。那里的SELECT语句找不到刚才插入的一条记录。这是目前表中唯一的记录。我做错了什么??
global $wpdb;
//Get post id for auction from post where auction is inserted. Used to track bids db.
$postid = get_the_id();
$starting_bid = 25;
$starting_email = "[email protected]";
//Creates jwp_bids table in database if it doesn\'t exist.
$table = $wpdb->prefix . "jwp_bids";
$charset_collate = $wpdb->get_charset_collate();
$sql = "CREATE TABLE IF NOT EXISTS $table (
`id` mediumint(15) NOT NULL AUTO_INCREMENT,
`bid_amt` decimal(10,2) NOT NULL,
`email` varchar(255) NOT NULL,
`bids_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
`post_id` mediumint(15) NOT NULL,
PRIMARY KEY (`id`)
) $charset_collate;";
require_once( ABSPATH . \'wp-admin/includes/upgrade.php\' );
dbDelta( $sql );
$count = $wpdb->get_var("SELECT COUNT(*)
FROM $table WHERE post_id IS NOT NULL");
if($count == 0){
$insert_db = $wpdb->insert(
$table,
array(
\'email\' => $starting_email,
\'bid_amt\' => $starting_bid,
\'post_id\' => $postid,
)
);
}
// We now have one record in the table representing the starting bid.
//Gets highest bid information and assigns to variables for display in post.
$highest_bid_info = $wpdb->get_results(
"SELECT max(bid_amt) AS bid, bid_time, email
FROM $table
WHERE post_id = $postid", ARRAY_A );
$highest_bid_info = array_shift ( $highest_bid_info );
$high_bid = $highest_bid_info[\'bid\'];
$high_bidder = $highest_bid_info[\'email\'];
$bid_time = $highest_bid_info[\'bid_time\'];