我遇到查詢問題。事實上,我想截斷一個表,然後將數據插入到同一個表中。只有一條記錄帶有TRUNCATE INSERT查詢
我的問題:當我執行這2個查詢INSERT記錄只有一行,我不知道爲什麼。當我工作正常之前執行沒有TRUNCATE的INSERT查詢。我能做些什麼來結合TRUNCATE和INSERT?
感謝
下面是代碼:
<?php
$base = mysql_connect ("***", "***", "***");
mysql_select_db ('***', $base) ;
$vider = "TRUNCATE TABLE drag";
mysql_query($vider);
// accept JSON parameter (and Un-quote string if needed)
$p = stripslashes($_REQUEST['p']);
// decode JSON object (it shouldn't be decoded as associative array)
$arr = json_decode($p);
// open loop through each array element
foreach ($arr as $p){
// set id, row index and cell index
$id = $p[0];
$row = $p[1];
$cell = $p[2];
// instead of print, you can store accepted parameteres to the database
print "Id=$id Row=$row Cell=$cell<br>";
$ajout = "INSERT INTO drag VALUES('','$id','$row','$cell')";
mysql_query($ajout);
mysql_close($base);
}
?>