My .csv
has duplicate clubs throughout the whole file, creating 1500 rows, the reason for this is that each duplicate row is an additional ClubTDays
, ClubTStartTime
and ClubTFinishTime
.
Meaning rather than write the club times in one cell, it has been exported with each new class duplicating the rest of the information.
This .csv.
is imported into Wordpress using All Import, then the clubs are shown on a google map with the right information.
My issue is that it can say the same address 8-9 times because of the day/times over rows.
Question:
The ClubNumber
is the id
of the club. Is there a way with php to merge rows with the same ClubNumber
, keep the address the same for these duplicates, but for the ClubTDays
/ ClubTStartTime
/ClubTFinishTime
differenciate, they're combined into one cell.
This way, the google map will only list the one address per club, but list several days that they opperate.
Here's some example code i'm working with:
$handle = fopen("CLUBEXP.csv", "r");
$row = 0;
$ClubNumberList = array();
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$ClubNumber = $data[0];
$ClubTDays = $data[19];
if ( array_key_exists($ClubNumber, $ClubNumberList) ) {
$ClubNumberList[$ClubNumber][] = $ClubTDays;
} else {
$ClubNumberList[$ClubNumber] = array($ClubTDays);
}
$row++;
}
print_r( $ClubNumberList );
The issue with this code is that it removes all over columns. It merges the day fine, but it doesn't copy over the rest.
Once these fields have been merged, I need to save the .csv
with a different name like "clubs-merged.csv" so I can import it through wordpress.
Can this be done? & Can anyone point me in the right direction?