0

I have a small doubt regarding the offsets. Suppose I have a csv file like this:

1
8 9 10 11 12 13 14 15 16 17 18 19 20

I am simply using fgetcsv function to retrieve data from csv to my php page. Here's the code: $fp = FOPEN ("so-csv.csv","r"); $data = FGETCSV ($fp, 1000, ",") symbol date . . .

data[0] shows "1" but data[1] is undefined offset. var_dump($data[1]) displays NULL. I believe I am accessing row-1 col-B of csv through data[1] which is null. How do I access next row (element 8)? Thnx

2 Answers2

1
while($data = fgetcsv($fp,1000, ",")) {
    // your processing code here
}

that's all you should need

jsickles
  • 421
  • 2
  • 7
  • Still can't get it done. Undefined offset error still persists. Can you tell me if there's a naming convention for the example data in csv file given in question?? – user3772084 Jun 25 '14 at 13:21
  • I would assume that your numbers are separated by commas... which isn't the case in your example. – jsickles Jun 25 '14 at 15:00
  • Also, `$data[1]` does not exist for each `$data` reference. The first row will have `$data[1]` undefined, and the second row will have `$data[1] = 9` – jsickles Jun 25 '14 at 15:02
0

The fgetcsv function only reads in one line at a time. To get the second line of the file, you simply need to call the function a second time.

ktbird7
  • 56
  • 8