Page 1 of 1

Row and data in csv

Posted: Sat Sep 03, 2005 5:28 am
by salto
Newbie here, any help most welcome!
I would like to echo a chosen field in a row in a csv file
this csv file has for example 23 columns and 35 rows

Code: Select all

<?php
$row = 0;
$handle = fopen("example.txt", "r");
while (($data = fgetcsv($handle, 10000, ",")) !== FALSE) {
   $num = count($data);
   $row++;
   for ($c=0; $c < $num; $c++){
       echo $data[1] ."<br>------<br>\n";

  }
}
fclose($handle);
?>
this echos $data[1] , of every row as many times as there are columns :(
I would like to echo only $data[1] of for example $row[3]
If this is possible, any help most welcome.
Thank you for your kind interest.

Posted: Sat Sep 03, 2005 8:22 am
by feyd

Code: Select all

<?php
$row = 0;
$handle = fopen("example.txt", "r");
while (($data = fgetcsv($handle, 10000, ",")) !== FALSE) {
   $num = count($data);
   $row++;
   if($row == 3)
   {
       echo $data[1] ."<br>------<br>\n";
   }
}
fclose($handle);
?>
:?

Posted: Sat Sep 03, 2005 8:37 am
by salto
Indeed, thanks very much! Great!