-4

Possible Duplicate:
how to extract data from csv file in php

I want to print an array from a CSV file. It contains 4 rows. First row with id numbers and second,third and fourth rows with corresponding values.

Depending on the values, I want to print the id number. Please help me guys as I am new to php.

Like if value == 1 , print_r($id)

but I am not sure how to point to that paticular id.

Community
  • 1
  • 1
user1694724
  • 61
  • 1
  • 5
  • 9

1 Answers1

-1

Have a look at fgetcsv(), it will help you out tremendously

I've adapted the example in the PHP docs to closer match my understanding of your needs.

<?php
if (($handle = fopen("test.csv", "r")) !== false) {
    while (($data = fgetcsv($handle) !== false) {
        // assuming 'id' is the first column
        // if id is 1, output the row...
        if ($data[0] == 1) {
            print_r($data);
        }
    }
    fclose($handle);
}
maček
  • 76,434
  • 37
  • 167
  • 198