我的最終目標是在插入新促銷後,使用新PK ID更新Dealers表中的現有列(promo_ids)。我想保留已設置的現有ID。這可能嗎?如果是這樣,任何正確的方向將是偉大的。我對SQL語句還很陌生。以下是我目前必須添加新促銷的代碼。插入SQL後更新
public function add_new_promo() {
global $wpdb;
$result = $wpdb->query(
$wpdb->prepare(
"
INSERT INTO $wpdb->gdp_promos
(promo, short_desc, long_desc, rebate_url, legal_copy, image_id, promo_headline, promo_line1, promo_desc, linkback_url, share_image_id, dealer_ids)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
",
$this->promo_data['promo'],
$this->promo_data['short_desc'],
$this->promo_data['long_desc'],
$this->promo_data['rebate_url'],
$this->promo_data['legal_copy'],
$this->promo_data['image_id'],
$this->promo_data['promo_line1'],
$this->promo_data['promo_headline'],
$this->promo_data['promo_desc'],
$this->promo_data['linkback_url'],
$this->promo_data['share_image_id'],
$this->promo_data['dealer_ids']
)
);
if ($result === false) {
$state = 'error';
$msg = __('There was a problem saving the new promo details, please try again.', 'gdp');
} else {
$_POST = array();
$state = 'updated';
$msg = __("promo {$this->promo_data['promo']} successfully added.", 'gdp');
}
add_settings_error ('add-promo', esc_attr('add-promo'), $msg, $state);
}
這看起來像同時刪除所有現有的促銷標識它將更新在經銷商處的表每一位經銷商用新的推廣ID。 –
你說得對。抱歉。我編輯過它。 –