我使用字符串构建了一个“INSERT INTO”MySQL 查询,但是这个查询只更新列“date”并返回“0”作为列“id”的值
$c= "2013-11-29 12:00:00";//whole code
$d= "2013-11-30 12:00:00";
$date_3 = date("Y-m-d g:i:s", strtotime("$c"));
$date_4 = date("Y-m-d g:i:s", strtotime("$d"));
$results = array($date_1);
$i = $date_3;
$allCane="";
while ($i <= $date_4) {
$i = date("Y-m-d g:i:s", strtotime($i));
array_push($results, $i);
$k= $i . "\n";
$chunks = str_split($k, 19);
$nexstring = join('\')', $chunks);
$cane = implode(', (\'{$id}\', \'', str_split($nexstring, 21));
$allCane .= $cane; // appends $cane to $allCane
$i = date("Y-m-d g:i:s",strtotime("+1 day", strtotime($i)));
}
$string ='(\'{$id}\', \' '.$allCane;
$string=substr($string,0,-12);
echo $string;//('{$id}', ' 2013-11-29 12:00:00'), ('{$id}', ' 2013-11-30 12:00:00')
$id=54;
$insert = mysql_query("INSERT INTO events (id, date) VALUES $string");
// i build the query using $string.
$insert的语法是正确的,但实际上我无法更新“id”列。
有什么方法可以将工作$id放入字符串中?