Hi, I hope you can help me. I have a CSV import working correctly. But I would love if it can skip the first two lines in the CSV file.
Best regards Kai
Hi, I hope you can help me. I have a CSV import working correctly. But I would love if it can skip the first two lines in the CSV file.
Best regards Kai
Hi @Teodor
We have an App we used to register all strokes we are using when playing Golf. When the round is finished, it is possible to download a CSV file, and for some reason, they have created a blank line on the second line. And the database is complaining. It will make it much more user-friendly if I can import this file directly. I am not sure we can do it a different way, maybe skip lines with Null values.
I have made this import earlier in PHP, and it works.
This is the old code. (made by help from Google)
move_uploaded_file($_FILES[“file”][“tmp_name”], “files/” . $_FILES[‘file’][‘name’]);
$file = “files/” . $_FILES[‘file’][‘name’];
$query = <<<eof
LOAD DATA LOCAL INFILE ‘$file’
INTO TABLE resultemp
CHARACTER SET utf8
FIELDS TERMINATED BY ‘;’
LINES TERMINATED BY ‘\r\n’
IGNORE 2 LINES
(placering,player,hcp,ToPar,Score)
eof;
if (!$result = mysqli_query($con, $query)) {
exit(mysqli_error($con));
}
$message = “CSV file successfully imported!”;
$query2 = “INSERT INTO resultater (resultater.playerID, resultater.placering, resultater.hcp,resultater.ToPar,resultater.Score) \n”
Hello,
You can use simple condition step, to check if the CSV row has a value. For example check if the ID(or whatever your identity column is called) column if the field has a value. If it has a value run database insert else, do nothing:
So under condition put the insert into the THEN steps, and leave ELSE steps empty.
Hi @Teodor
It is not working. It fails on the blank line. Maybe I am too green to understand this. The file looks like this:
;Player;HCP;To Par;Score
1.;Kalle Dyngbo;27;-3;39
T2.;Petter Reinstrup;16;+1;35
T2.;Karsten Paulsen;21;+1;35
4.;Kalle Banan;21;+2;34
I insert all the records in a temp table and enrich the table with some values from some custom selected. And it works well.
I have tested with the condition on all Fields. We do not have an ID identity column, the only place we have a unique value is the Player name. During an insert, I remove all the “.” and T from the first column.
Best regards Kai
It doesn’t need to be an unique field, you just need to check if the field is empty.
Can you attach a sample csv file here, which I can test with?
Thanks, I will check that.
I just tested with the settings i provided in my earlier post and it works as expected. I imported only the expected fields:
So these are the steps needed:
;
as in your csv this is the delimiter:{{Player}}
field has a value. Select this through the data picker:Hi @Teodor
Thanks for all the help. It is working the way you are doing it. The only problem is that I need the first “blank” column. Can we fix that somehow?