我有一个csv文件,每天晚上上传第二天的工作。
这是插入命令:
$handle = fopen($_FILES['filename']['tmp_name'], "r");
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$data = array_map('mysql_real_escape_string', $data);
if($i>0) {
$import="INSERT into patientinfo(PATNUM,PATNAME,AGE,SEX,SCHDT,SCHTM,SURGEON,TASK,PTIS1COMP,PTIS2COMP,PTIS3COMP,SERVTYPE,DURATION,ORRoom,DIAG01,COMMENT1,COMMENT2,COLBY_Arrival_time_1,UR_PreAdmission_Plan_1,UR_IMFM_req_1,UR_IMFM_req_2,Smoke_Signal_MRSA_Positive_1,Smoke_Signal_VRE_Positive_1) values('$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]')";
mysql_query($import) or die(mysql_error());
}
$i++;
}
我遇到的问题是无论我做什么,UR_IMFM_req_2
字段总是上传到最后一列。如果我删除了UR_IMFM_req_2
,字段和最后一个$data[22]
字段并从csv中删除了该列,则上传就可以了。
以下是一些示例数据 - 只有Judy Johnson正确上传:
PATNUM 123456 123457 123458
PATNAME Jane Doe Sandy Smith Judy Johnson
AGE 35 47 60
SEX F F F
SCHDT 30816 30816 30816
SCHTM 0700 0915 1200
SURGEON Surgeon1 Surgeon2 Surgeon1
TASK Hip Shoulder Knee
PTIS1COMP Ins1 Ins1 Ins1
PTIS2COMP Ins2 None None
PTIS3COMP Ins3 None None
SERVTYPE INPT OBS INPT
DURATION 1:30 0:45 2:00
LOCADESC OR1 OR2 OR1
DIAG01 Hip Shoulder Knee
COMMENT1 test test test
COMMENT2 test test test
COLBY_Arrival_time_1 06:30 07:00 10:00
UR_PreAdmission_Plan_1 none Talk to None
UR_IMFM_req_1 IMFM Req
UR_IMFM_req_2 IMFM Req IMFM Req
Smoke_Signal_MRSA_Positive_1 Yes
Smoke_Signal_VRE_Positive_1