fgetcsv
| From: | Danny Brow | Date: | Wed, 09 Jan 2008 22:35:25 +0000 |
| Subject: | fgetcsv | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-266979@lists.php.net to get a copy of this message | ||
Hi Everyone,
I'm trying to compare a value to the first field in a csv fILE (example
of the data below). Using while takes too long and I can't figure out
how to compare just one row at a time. I've tried some variations of the
following.
//Common for all trials
$demoID = fopen("newDemoID.csv", "r");;
$ID = "43";
$data = fgetcsv($demoID);
First try with while:
/*
while ($data) {
if ($data[0] == $wolfID) {
print $data[1] . "," . $data[2] . "," . $data[3] .
".\n";
}
}
*/
Takes for every.
I can't use just the below because it only compares the first row.
/*
if ($data[0] == $wolfID) {
print $data[1] . "," . $data[2] . "," . $data[3] . ".\n";
}
*/
I know this is simple, but I've hit codes block due to lack of sleep.
Thanks,
Dan
Sample Data:
> 5,1,"Smith","Myrtle"
> 6,2,"Smith","Carita"
> 7,3,"Smith","Paul"
> 8,4,"Smith","Donald"
--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.