我正在尝试从 csv 文件导入数据,该文件具有以下格式:
173,antony,xds1079,Antony,Pran,Pran Antony,,452522252,,,,antpran@hotmail.com,,,,,Yes,Yes,No,pricelist.xls
18,john,smithison22,John,Smith,Smith Jon,,545455726,,,,johnsmith01@in.com,,,,,Yes,Yes,No,pricelist.xls
22,nikolas,Brand44eBerg,Nikolas,Brandeberg,Brandeberg and sons ,,454554552,,,,brand88@freemail.co.uk,,,,,Yes,Yes,No,pricelist.xls
将其插入 mySQL 时,第一行的最后一个字段同时 pricelist.xls
包含和18
。但是18
应该放在下一行,因为它是 id 字段。
这是我使用的php代码:
if ($_FILES[csv][size] > 0) {
//get the csv file
$file = $_FILES[csv][tmp_name];
$handle = fopen($file,"r");
//loop through the csv file and insert into database
do {
if ($data[0]) {
mysql_query("INSERT INTO customers_tmp (id,username, password, firstname, lastname, companyname, companyposition, phone1, phone2, mobilephone, fax, email, address, afm, doy, website, active, wholesaling , wholesaling_bulk , pricecatalog) VALUES
(
'".addslashes($data[0])."',
'".addslashes($data[1])."',
'".addslashes($data[2])."',
'".addslashes($data[3])."',
'".addslashes($data[4])."',
'".addslashes($data[5])."',
'".addslashes($data[6])."',
'".addslashes($data[7])."',
'".addslashes($data[8])."',
'".addslashes($data[9])."',
'".addslashes($data[10])."',
'".addslashes($data[11])."',
'".addslashes($data[12])."',
'".addslashes($data[13])."',
'".addslashes($data[14])."',
'".addslashes($data[15])."',
'".addslashes($data[16])."',
'".addslashes($data[17])."',
'".addslashes($data[18])."',
'".addslashes($data[19])."'
)
");
}
} while ($data = fgetcsv($handle,1000,",","'"));
//
//redirect
header('Location: import.php?success=1'); die;
}
有谁知道我应该怎么做才能让 id 进入下一行而不是最后一个字段?