简体   繁体   English

在表格中插入多行

[英]Inserting multiple rows into table

So I basically have 2 arrays with a lot of numbers in them, I implode them: 所以我基本上有2个数组,其中有很多数字,然后将它们分解:

 $array1 = implode(", ", $array1);
 $array2 = implode(", ", $array2);

When I echo $array1 and $array2 it looks okay, numbers separated by commas 当我回显$ array1和$ array2时,看起来不错,数字之间用逗号分隔

But when I use: 但是当我使用时:

 "INSERT INTO table1 (array1, array2) VALUES ('$array1', '$array2')";

It only inserts first number (which is the first row in the csv file), what should I do now? 它仅插入第一个数字(即csv文件中的第一行),我现在该怎么办?

Possible solution in it's most basic form 最基本形式的可能解决方案

$array1 = Array(1,2,3,4,5);
$array2 = Array("one","two","three","four","five");

while(count($array1)>0){
    $a1 = array_shift($array1);
    $b1 = array_shift($array2);
    mysql_query("INSERT INTO table (numeric,alpha) VALUES('$a1','$b1')");
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM