我有一個數組是這樣的:插入PHP關聯數組MySQL表
Array ( [0] => 08/21/13 [1] => 08/21/13 [2] => 08/21/13 [3] => 08/21/13 [4] => 08/21/13 [5] => 08/21/13 )
我怎樣才能把它插入到MySQL數據庫?
我有一個數組是這樣的:插入PHP關聯數組MySQL表
Array ( [0] => 08/21/13 [1] => 08/21/13 [2] => 08/21/13 [3] => 08/21/13 [4] => 08/21/13 [5] => 08/21/13 )
我怎樣才能把它插入到MySQL數據庫?
PHP:
$query = "INSERT INTO tbl (your_date_column_name) VALUES "
. "('" .implode("'),('", $your_array)."')";
MySQL Manual說:使用VALUES語法可以插入多行
INSERT語句。 爲此,請包含多個列值列表,每個列表值都包含在 括號內,並用逗號分隔。
所以,SQL變,
INSERT INTO tbl (your_date_column_name)
VALUES('08/21/13'),('08/21/13'),('08/21/13')
,('08/21/13'),('08/21/13'),('08/21/13');
你能解釋一下答案有什麼問題嗎?如果有的話,你的問題也有問題。請解釋這個問題,而不是... – hsuk
你餵了幫助吸血鬼。 –
謝謝,這解決了我的問題... hahahahaha – yayantritaryana
使用的foreach
首先存儲陣列,以一個可變
$a=array('08/21/13','08/21/13','08/21/13','08/21/13','08/21/13','08/21/13');
foreach($a as $key=>$value){
$date=date_create($value);
$date1=date_format($date,"Y-m-d");
//Here Your Insert Query
$query=mysql_query("INSERT INTO TABLENAME SET date='".$date1."'");
}
手段要插入此'陣列 ( [0] => 08/21/13 [1] => 08/21/13 [2] => 08/21/13 [3] => 08/21/13 [4] => 08/21/13 [5] => 08/21/13 )'表裏面還是數組的值? –
我想插入數值列表(08/21/13)列表日期在mysql表 – yayantritaryana
序列化不適合你嗎? – Roopendra