My favorites | Sign in
Project Logo
                
Search
for

Simple data access object for csv files in php5.

by Kazuyoshi Tlacaelel.

Some features

Cells

  1. fillCell cell value filler
  2. getCell cell fetcher
  3. hasCell checks if a coordinate is valid

Headers

  1. countHeaders header counter
  2. createHeaders header creator
  3. getHeaders header fetcher
  4. setHeaders header injector

Columns

  1. appendColumn column appender
  2. fillColumn collumn data injector
  3. getColumn column fetcher
  4. hasColumn column existance checker
  5. removeColumn column remover
  6. walkColumn column walker

Must see

  1. __construct data load initialize
  2. connect header and row relationship builder
  3. getRawArray raw data as array
  4. isSymmetric data length/symmetry checker
  5. load csv file loader
  6. settings settings alterator
  7. symmetrize all rows length equalizer
  8. walkGrid grid walker

Rows

  1. appendRow row appender
  2. countRows row counter
  3. fillRow fillRow
  4. getAsymmetricRows asymmetric data fetcher
  5. getRow row fetcher
  6. getRows multiple row fetcher
  7. hasRow row existance checker
  8. removeRow row remover
  9. walkRow row walker
Updated Dec 18, 2008 by kazu....@gmail.com
fillRow  

Method:fillRow

fillRow

Replaces the contents of cells in one given row with $values.

sample of a csv file "my_cool.csv"

name,age,skill
john,13,knows magic
tanaka,8,makes sushi
jose,5,dances salsa

if we load the csv file and fill the second row with new data?

// load the library
require_once 'File/CSV/DataSource.php';
$csv = new File_CSV_DataSource;

// load csv file
$csv->load('my_cool.csv');

// fill exitent row
var_export($csv->fillRow(1, 'x'));

output

true

now let's dump whatever we have changed

var_export($csv->connect());

output

array (
0 =>
array (
'name' => 'john',
'age' => '13',
'skill' => 'knows magic',
),
1 =>
array (
'name' => 'x',
'age' => 'x',
'skill' => 'x',
),
2 =>
array (
'name' => 'jose',
'age' => '5',
'skill' => 'dances salsa',
),
)

now lets try to fill the row with specific data for each cell

var_export($csv->fillRow(1, array(1, 2, 3)));

output

true

and dump the results

var_export($csv->connect());

output

array (
0 =>
array (
'name' => 'john',
'age' => '13',
'skill' => 'knows magic',
),
1 =>
array (
'name' => 1,
'age' => 2,
'skill' => 3,
),
2 =>
array (
'name' => 'jose',
'age' => '5',
'skill' => 'dances salsa',
),
)
  1. Argument integer $row the row to fill identified by its key
  2. Argument mixed $values the value to use, if a string or number

is given the whole row will be replaced with this value. if an array is given instead the values will be used to fill the row. Only when the currently loaded dataset is symmetric

fillCell(), appendRow()


Sign in to add a comment
Hosted by Google Code