HI
I am very confused right now guys. I have no idea how to evaluate my upload script. This adds CSV lines into my phpmyadmin table and it works fine, but i want to make it more user friendly so users could simply `save as` an XLS file into a CSV file without making any adjustments. And so the program would do most of the work from there. So if my CSv file looks like this:
, ,, ,,,,,
some word, random, ,,,,
#Batch 312-313
312,John Smith, New Jersey,, //line 1
313, Ana White, California,, //line 2
#Batch 314-315
314, Greg Long, Mexico //line 3
315, Jane Snow, Texas,, //line 4
Prepared by:, Jack Brown, CPA
I need help on how to add only the four lines into the fields: `number`, `name`, `address`
How do i disregard any other things in the CSV except for words that should be on my database?
Thank you for your time, and have a nice day.
csv to sql convert:how to evaluate CSV lines
Moderator: General Moderators
Re: csv to sql convert:how to evaluate CSV lines
It looks like you want only the lines that
a) Begin after the first "#Batch" line
b) Have a number in the first field
So
a) Begin after the first "#Batch" line
b) Have a number in the first field
So
Code: Select all
open the file
while not at the end of the file {
read a line with fgets
if the line starts with "#Batch" then exit this loop
}
while not at the end of the file {
read a line using fgetcsv
if the size of the returned array is at least 3 and the first item is a number then {
do whatever you want with the data
} else if the first item is not a number and does not start with "#Batch" then {
exit this loop
}
}
close the fileRe: csv to sql convert:how to evaluate CSV lines
Thanks tasairis, i'll try this out