I have an automated process which uploads a comma separated
spreadsheet (csv) and inserts it into a database:
$sql = "LOAD DATA INFILE '".$uploadfile. "' INTO TABLE `tbl_tracking`
FIELDS TERMINATED BY ','".
"OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\n'".
"( `tr_trackno` , `tr_ordernum` , `tr_shipname` , `tr_shipaddr` ,
`tr_citystate` , `tr_zip` , `tr_weight` , `tr_method` , `tr_shipdate`
)";
Now, one of the columns is supposed to be a 5-digit integer
column...but the person who generates the spreadsheet (a 3rd party I
have no control over) ocassionally has other text in that column in
some records. Say 3 out of 50.
For example, what it's supposed to have is data like: '12345', but
instead it sometimes has: '12345 Some Extra Text Here', and sometimes
there will be a doublequoute in front: '"12345 Some Extra Text'.
No my question is, is there a way to pull a 5-digit number out of a
field? If I could be gaurenteed that the number would always be the
1st 5 digits, I could just do a len() and then crop everything after
the 5th character. But when there's ocassionally a character in front
of the number, that won't work.
What if I make the database column a 5-digit init field? Would it
automatically only insert the 5-digit part of the field? (Doubt it.)
Thanks for any suggestions!!
Liam
spreadsheet (csv) and inserts it into a database:
$sql = "LOAD DATA INFILE '".$uploadfile. "' INTO TABLE `tbl_tracking`
FIELDS TERMINATED BY ','".
"OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\n'".
"( `tr_trackno` , `tr_ordernum` , `tr_shipname` , `tr_shipaddr` ,
`tr_citystate` , `tr_zip` , `tr_weight` , `tr_method` , `tr_shipdate`
)";
Now, one of the columns is supposed to be a 5-digit integer
column...but the person who generates the spreadsheet (a 3rd party I
have no control over) ocassionally has other text in that column in
some records. Say 3 out of 50.
For example, what it's supposed to have is data like: '12345', but
instead it sometimes has: '12345 Some Extra Text Here', and sometimes
there will be a doublequoute in front: '"12345 Some Extra Text'.
No my question is, is there a way to pull a 5-digit number out of a
field? If I could be gaurenteed that the number would always be the
1st 5 digits, I could just do a len() and then crop everything after
the 5th character. But when there's ocassionally a character in front
of the number, that won't work.
What if I make the database column a 5-digit init field? Would it
automatically only insert the 5-digit part of the field? (Doubt it.)
Thanks for any suggestions!!
Liam
Comment