Categories > TinyButStrong general >

CSV example?

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: rcjordan
Date: 2009-01-22
Time: 21:04

CSV example?

Are there any examples showing how to set up TBS using the CSV plugin? I've tried searching on 'CSV files' and assorted CSV terms here but seem to only get false-positive results.
By: TomH
Date: 2009-01-22
Time: 22:19

Re: CSV example?

Hi

The CSV plugin class includes a note showing the syntax to use it as a pseudo database.
That is...
MergeBlock('result', 'csv', 'test.csv');
Note: You can specify the CSV delimitor and length with this constant to define before MergeBlock method with csv source.
TBS_CSV_DELIMITER TBS_CSV_LENGTH */

Have you installed and tested any code attempting to use it?

Show us your php and html code and any errors you are getting...

By: rcjordan
Date: 2009-01-22
Time: 23:22

Re: CSV example?

Hi Tom,

testdata.csv
a1,a2,a3
b1,b2,b3
c1,c2,c3
d1,d2,d3

templateCSV.html
<html>
<body>
<table>
   <tr><td>[block1.$;block=tr]</td></tr>
</table>
</body>
</html>

phpTestcsvdb.php
<?
include_once('tbs_class.php');
include_once('tbsdb_csv.php');
$TBS =& new clsTinyButStrong ;
$TBS->LoadTemplate('templateCSV.html') ;
$TBS->MergeBlock('block1', 'csv', 'testdata.csv');
$TBS->Show() ;
?>

'tbs_class.php' and 'tbsdb_csv.php' (ver php4) are in the same directory.

Results:
1
2
3

Looks like row count - 1
By: rcjordan
Date: 2009-01-23
Time: 00:06

Re: CSV example?

got it working. the keys need to be defined in the first row of the data.
col1,col2,col3
a1,a2,a3
b1,b2,b3
c1,c2,c3

Seems like I should be able to call them by by a field number. I tried field1, which I saw in some of the documentation but that didn't work. Got error message "TinyButStrong Error in field [block1.field1...] : item 'field1' is not an existing key in the array."
By: TomH
Date: 2009-01-23
Time: 03:12

Re: CSV example?

Great to learn about the first row issue, thanks.

Out of curiosity... did you try to call the fields by [block1.col1] ?

Thx,
By: rcjordan
Date: 2009-01-23
Time: 17:10

Re: CSV example?

With the first data line declaring the values, here's how I set up the call (playing around with conditional now)
<html>
<body>
<table>
   <tr><td>
   [block1.col1;if [val]==b1;then '===>B1';else [val];block=tr]</td></tr>
</table>
</body>
</html>

Did I interpret your question correctly?
By: TomH
Date: 2009-01-23
Time: 21:18

Re: CSV example?

Yes,

that's what I meant,

thanks very much!