Row and data in csv

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
salto
Forum Commoner
Posts: 31
Joined: Thu Jul 04, 2002 7:50 am

Row and data in csv

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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);
?>
:?
salto
Forum Commoner
Posts: 31
Joined: Thu Jul 04, 2002 7:50 am

Post by salto »

Indeed, thanks very much! Great!
Post Reply