質問編集履歴
1
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -40,7 +40,7 @@
|
|
40
40
|
|
41
41
|
|
42
42
|
|
43
|
-
```
|
43
|
+
```jquery
|
44
44
|
|
45
45
|
var DB_action = function(){
|
46
46
|
|
@@ -64,7 +64,7 @@
|
|
64
64
|
|
65
65
|
|
66
66
|
|
67
|
-
|
67
|
+
var move_users_json = JSON.stringify(move_users);
|
68
68
|
|
69
69
|
|
70
70
|
|
@@ -74,13 +74,13 @@
|
|
74
74
|
|
75
75
|
url : ajaxurl,
|
76
76
|
|
77
|
-
dataType : '
|
77
|
+
dataType : 'text',
|
78
78
|
|
79
79
|
data : {
|
80
80
|
|
81
81
|
'action' : 'ajax_test',
|
82
82
|
|
83
|
-
users_ID : [
|
83
|
+
users_ID : [move_users_json],
|
84
84
|
|
85
85
|
}
|
86
86
|
|
@@ -136,7 +136,121 @@
|
|
136
136
|
|
137
137
|
```
|
138
138
|
|
139
|
-
|
139
|
+
```php
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
function ajax_test() {
|
144
|
+
|
145
|
+
// print $_POST['users_ID'];
|
146
|
+
|
147
|
+
global $wpdb;
|
148
|
+
|
149
|
+
$posts_title = $_SESSION['toukou_title'];
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
//トランザクションを開始-------------------------------------------------------------------
|
154
|
+
|
155
|
+
$wpdb->query("START TRANSACTION"); // BEGINでもOK
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
//削除----------------------------------------------------------------------
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
$query = "
|
164
|
+
|
165
|
+
DELETE FROM $wpdb->test_master
|
166
|
+
|
167
|
+
WHERE posts_title = %s
|
168
|
+
|
169
|
+
";
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
$result_delete = $wpdb->query(
|
174
|
+
|
175
|
+
$wpdb->prepare($query , $posts_title));
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
//追加----------------------------------------------------------------------
|
180
|
+
|
181
|
+
$move_users = ($_POST['users_ID'][0]);
|
182
|
+
|
183
|
+
$user_count = count($move_users);
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
for ($i = 0; $i < $user_count; $i++) {
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
$query = "
|
192
|
+
|
193
|
+
INSERT INTO $wpdb->test_master
|
194
|
+
|
195
|
+
(posts_title, user_login)
|
196
|
+
|
197
|
+
VALUES (%s , %s)
|
198
|
+
|
199
|
+
";
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
$result_insert = $wpdb->query(
|
204
|
+
|
205
|
+
$wpdb->prepare($query , $posts_title , $move_users[$i]));
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
}
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
//トランザクション処理-------------------------------------------------------------------
|
214
|
+
|
215
|
+
if( $result_delete >= 0 && $result_insert >= 0){
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
$wpdb->query('COMMIT'); // Commit
|
220
|
+
|
221
|
+
print ('成功');
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
}else{
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
$wpdb->query('ROLLBACK');// Rollback
|
230
|
+
|
231
|
+
print ('失敗');
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
}
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
exit();
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
}
|
244
|
+
|
245
|
+
add_action('wp_ajax_ajax_test','ajax_test');
|
246
|
+
|
247
|
+
add_action('wp_ajax_nopriv_ajax_test','ajax_test');
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
```
|
140
254
|
|
141
255
|
|
142
256
|
|