Export table in hooks as csv

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
angus
Veteran Member
Posts: 128
Joined: 2020-05-28 22:27

Export table in hooks as csv

Post by angus » 2021-10-27 15:58

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)
AppGini 22.13

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Export table in hooks as csv

Post by pbottcher » 2021-10-27 18:19

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?
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

angus
Veteran Member
Posts: 128
Joined: 2020-05-28 22:27

Re: Export table in hooks as csv

Post by angus » 2021-10-27 20:48

its the generated csv thats the issue pbottcher.
example.png
example.png (6.74 KiB) Viewed 1620 times
AppGini 22.13

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Export table in hooks as csv

Post by pbottcher » 2021-10-27 20:57

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
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

angus
Veteran Member
Posts: 128
Joined: 2020-05-28 22:27

Re: Export table in hooks as csv

Post by angus » 2021-10-28 20:46

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?
AppGini 22.13

angus
Veteran Member
Posts: 128
Joined: 2020-05-28 22:27

Re: Export table in hooks as csv

Post by angus » 2021-10-28 23:34

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.
AppGini 22.13

Post Reply