此查詢有效:
$player_id = $_POST['player_id'];//array $ids = explode(',',$player_id); $in = implode(',', array_fill(0, count($ids), '%d')); $wpdb->query($wpdb->prepare("DELETE FROM {$player_table} WHERE id IN ($in)", $ids));
這不會:
$disabled = $_POST['disabled']; $media_id = $_POST['media_id'];//array $ids = explode(',',$media_id); $in = implode(',', array_fill(0, count($ids), '%d')); $wpdb->query($wpdb->prepare("UPDATE {$media_table} SET disabled = %s WHERE id IN ($in)", $disabled, $ids));
我不明白為什麼。
P粉5292450502023-09-13 09:29:15
您需要將IDS分散為單獨的參數,以符合查詢中的所有%s
。使用...
語法來實作。
$wpdb->query($wpdb->prepare("UPDATE {$media_table} SET disabled = %s WHERE id IN ($in)", $disabled, ...$ids));