【发布时间】:2015-08-17 10:19:48
【问题描述】:
我的查询有问题。事实上,我想截断一个表,然后将数据插入到同一个表中。
我的问题:当我执行这两个查询时,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);
}
?>
【问题讨论】: