gpt4 book ai didi

上传时PHP跳过CSV中的第一行

转载 作者:行者123 更新时间:2023-11-29 04:09:08 27 4
gpt4 key购买 nike

我有这个上传 CSV 并将数据插入数据库的 PHP 代码,一旦它在 while 循环中上传,它只从 CSV 中选择一行:

//do upload
if (is_uploaded_file($_FILES['dd_submission_form']['tmp_name']))
{
echo "<h3>" . "File ". $_FILES['dd_submission_form']['name'] ." uploaded successfully." . "</h3>";
echo '<h3>Display file contents:</h3>';
//readfile($_FILES['dd_submission_form']['tmp_name']);
}

//Import uploaded file to Database
$handle = fopen($_FILES['dd_submission_form']['tmp_name'], "r");

fgetcsv($handle, 1000, ",");

while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
{
$sql="SELECT * from customer where directdebit_reference = '".$data[0]."' ";
echo $sql;
$rs=mysql_query($sql,$conn) or die(mysql_error());
$customer=mysql_fetch_array($rs);
if(mysql_num_rows($rs) > 0)
{
$sql2="INSERT into dd_submissions (customer_seq, dd_reference, sortcode, account_number, account_name, amount, bacs_code, invoice_no, title, initial, forename, surname, salutation_1, salutation_2, address_1, address_2, area, town, postscode, phone, mobile, email, notes) values ('".$customer["sequence"]."', '$data[0]', '$data[1]', '$data[2]', '$data[3]', '$data[4]', '$data[5]', '$data[6]', '$data[7]', '$data[8]', '$data[9]', '$data[10]', '$data[11]', '$data[12]', '$data[13]', '$data[14]', '$data[15]', '$data[16]', '$data[17]', '$data[18]', '$data[19]', '$data[20]', '$data[21]', '$data[22]')";
$rs2=mysql_query($sql2,$conn) or die(mysql_error());
}
}
fclose($handle);
print "<br><br><h3>Successfully Imported Clients</h3><br>";

最佳答案

只需单独处理循环之前的第一行,不对其进行任何操作以跳过它。

fgets($handle); 然后你的循环

关于上传时PHP跳过CSV中的第一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18020003/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com