Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

CVS import - unknown number of columns


Reply


2 Posts   369 Views

Avatar
Futureweb

Community Member, 233 Posts

17 May 2012 at 5:42pm

Hi,

I have a situation where my client will be uploading CSV files.

The first column defines various 'questons', and the subsequent rows define different peoples answers.

There are about 100 rows (questions), and the number of columns (answers) keeps growing.

Instead of creating a database table with all the rows matching the CSV file, I was thinking of having a table with 'question, answer, name'
name is the name of the person - which is the first question.

So

name: jon , Stu , Bob
age: 31, 20, 56
nationality: uk, nz, usa
height: 5ft, 6ft,2ft

becomes a serious of rows

question: answer: name
age: 31, jon
nationality: uk, jon
height: 5ft, jon
age: 20, Stu
nationality: nz, Stu
height: 6ft, Stu
age: 56, Bob
nationality: usa, Bob
height: 2ft, Bob

I would easily be able to search through this, and if the client adds more questions (rows) to the CSV file they just get loaded in.

However, I'm not really sure where to start... Anyone have any ideas?

Avatar
swaiba

Forum Moderator, 1799 Posts

17 May 2012 at 8:08pm

Hi,

Look into extending "CsvBulkLoader". function processRecord this will allow you to read the csv and write to any number of dataobjects with any logic that you require