Categories > TinyButStrong general >

CSV, coma, or !#! to implement

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: gerard
Date: 2010-04-14
Time: 00:19

CSV, coma, or !#! to implement

Hi,

I have done a guestbook in flat file a few years ago, today I have tried to figure a way of using this wanderful template system to read that flat file.

My php script reads the flat file database (db) and presents the results to screen.

The flat file structure is between the next ---- 2 lines.
------------------------------------------------------------
1!#!name!#!surname!#!address
2!#!name2!#!surname2!#!address2
.....
n!#!namen!#!surnamen!#!addressn

-----------------------------------------

It creates from 1 to n the db, and reads from it.

I cannot figure a way to put TBS to read such file.
any help please?

Thanks in advance, Gerard



By: TomH
Date: 2010-04-14
Time: 03:09

Re: CSV, coma, or !#! to implement

Hi

While I cannot see the code from your old application... I would have to guess that somewhere in there you had a php routine that decoded each line in the flat file so that the individual fields could be displayed.

That's one place that you could begin to migrate your code.

TBS only requires that the data to be displayed be contained in an array or object -- so you just need to use that old routine to create the array that TBS will use in the MergeBlock process.

The following psuedo-code might illustrate...
$records = file('flatfile_name.ext');

foreach( $records AS $rec_num=>$record ) {
// read the line by the !#! delimeter into fields
$fields = explode("!#!", $record);
$TBS_Array[] =
array("id"=>$fields[0],"name"=>$fields[1],"surname"=>$fields[2],"address"=>$fields[3]);
}

$TBS->MergeBlock('blk1', $TBS_Array);

Hope that gets you started,