它可能很简单,我想加入或合并数组并相应地将它们插入数据库。数组结构如下:
$movies = array();
$songs = array();
$singers = array();
通过html dom解析器获取数组数据
foreach($somevar as $val){
$movies[] = $val; // 7 results
}
foreach($somevar as $val){
$songs[] = $val; // 7 results
}
foreach($somevar as $val){
$singers[] = $val; // 7 results
}
现在我有3个数组,每个数组都以[0] to [6]
为索引。我想将它们插入数据库。我如何加入每个第一个值与升序。
数据库表就像:
INSERT INTO tbl_name (movie_name,song_title,singer_name) VALUES('$movie', '$song','$singer')
我无法弄清楚如何相应地加入不同数组的值。请指教,任何帮助将不胜感激。
答案 0 :(得分:1)
如果那些是数组并行数组,您可以尝试
$movies = array("movie1","movie2","movie3","movie4","movie5","movie6");
$songs = array("songs1","songs2","songs3","songs3","songs4","songs5","songs6");
$singers = array("singers1","singers2","singers3","singers4","singers5","singers6");
$query = '';
for($i=0; $i<count($movies); $i++){
$query .= "INSERT INTO tbl_name (movie_name,song_title,singer_name) VALUES('$movies[$i]', '$songs[$i]','$singers[$i]');";
}
//=======do multi query execution here