$words = 'word1,word2,word3';
我如何将这些数据转换为以下结构:
MySQL 表:
id value
1 word1
2 word2
3 word3
我在想什么:
$separated = explode(",",$words);
//do some kind of loop
INSERT INTO table (value) VALUES ('$something');
我想我很讨厌循环:/
谢谢
$words = 'word1,word2,word3';
我如何将这些数据转换为以下结构:
MySQL 表:
id value
1 word1
2 word2
3 word3
我在想什么:
$separated = explode(",",$words);
//do some kind of loop
INSERT INTO table (value) VALUES ('$something');
我想我很讨厌循环:/
谢谢
$wordArray = explode(",", $words);
$stmt = "INSERT INTO table (column) VALUES ('" . implode("'), ('", $wordArray) . "')";
这将产生:
INSERT INTO table (column) VALUES ('word1'), ('word2'), ('word3')
做一个简单的循环,例如:
foreach($separated as $seperate){
$sql .= "INSERT INTO table (value) VALUES ('$seperate')";
}