Page 1 of 1

Export table in hooks as csv

Posted: 2021-10-27 15:58
by angus
Hello board, I use the following to export a table to a csv. This csv is then used as the drop downs in another page.

Code: Select all

function update_Teams_list() {
               // Update Teams
               $Teams = array();
               $res = sql("select Teams from Teams order by Teams", $eo);
               while($row = db_fetch_assoc($res))
                    $Teams[] = $row['Teams'];
               // save the Teams to the options list file
               $list_file = dirname(__FILE__) . '/Leagues.TeamsList.csv';
               @file_put_contents($list_file, implode(';;', $Teams));
	}
This has worked ok for years but in the last week one of the teams has a comma in it. This has now altered the way the csv is output. Rather than everything being in cell A1, everything is split between A1 & A2 (where the comma is it splits the data).

My hope is somebody can help me fix this so that everything is output into the one cell again (A1)

Re: Export table in hooks as csv

Posted: 2021-10-27 18:19
by pbottcher
Hi,
not sure if I get your problem. Is your app not working correctly, or is the generated csv that you open in excel the question?

Re: Export table in hooks as csv

Posted: 2021-10-27 20:48
by angus
its the generated csv thats the issue pbottcher.
example.png
example.png (6.74 KiB) Viewed 2702 times

Re: Export table in hooks as csv

Posted: 2021-10-27 20:57
by pbottcher
Hi,

but if you need the csv as base for the drop down, that should not matter. In Excel you can import the file and just not use the comma as separator, but the tab instead.

As you write it is a csv file, so actally it is a text file that should look like
Team1;;Team2;;Team3;;Team4, and Team6

if you open it with notepad

Re: Export table in hooks as csv

Posted: 2021-10-28 20:46
by angus
I don’t want to manually import a list though. This is a table as another team updates the contents. Saves me time having to do it manually each time.

Thanks for your help but doing this manually is not an option, anyone else have any idea?

Re: Export table in hooks as csv

Posted: 2021-10-28 23:34
by angus
found a solution to this. I amended the dml file to use a txt option instead of csv. Changed the delimiter from ',' to ';' and all is working ok now. its not perfect but its a good solution for me at the moment.