當用戶提交表單時,我正努力在動態字段中使用自動增量ID。如何爲每個提交條目更新自定義表? &我們應該如何從自定義表中獲取ID?以聯繫表格形式獲取自動增量ID 7
創建表有自動遞增:
function create_db() {
global $wpdb;
$charset_collate = $wpdb->get_charset_collate();
$table_name = $wpdb->prefix . "id_count";
if($wpdb->get_var("show tables like '$table_name'") != $table_name) {
$sql = "CREATE TABLE $table_name (
`id` mediumint(9) NOT NULL AUTO_INCREMENT,
`name` mediumtext NOT NULL,
UNIQUE KEY id (id)
)$charset_collate;";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
}
}
add_action("init", "create_db");
當表單提交:
function your_wpcf7_posted_data($posted_data) {
global $wpdb;
$name = $posted_data['your-name'];
$table_name = $wpdb->prefix . "id_count";
$posted_data['cf7-counter'] = $wpdb->insert_id;
);
作爲一般規則:不要使用您的表單中的ID,它將在您插入dat時自動創建一個在數據庫中。 –
有沒有我可以看的資源?目前我的表單向cfdb插件發送,不包含自動增量列http://cfdbplugin.com/ – mark5
是的,我注意到了這一點。但是你可能仍然會得到一個有效的自動增量值?問題是:爲什麼你想在你的表單中的自動增量值?更新? –