Re: fgetcsv

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



You are so right, takes all of 0.122 s to process the whole file with
the fgetcsv inside the while loop.... Guess I need to look up why this
was the problem.

Thanks everyone!


On Wed, 2008-01-09 at 20:59 -0600, Richard Lynch wrote:
> 6500 rows is chump-change.
> 
> You probably don't have the fgetcsv inside the while loop to get past
> the first row... :-)
> 
> On Wed, January 9, 2008 6:09 pm, Danny Brow wrote:
> > I need to compare the first field of each row. But this idea is shot
> > to
> > hell, i've been running one of the examples on the file and it's been
> > about an hour+ already... 6500 records have to be checked... I think
> > MySQL is calling my name right now.
> >
> > Thanks,
> > Dan
> >
> >
> > On Thu, 2008-01-10 at 09:59 +1100, Chris wrote:
> >> Danny Brow wrote:
> >> > 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.
> >>
> >> So are you trying to compare the first column or the first row?
> >> You've
> >> said you want to compare both.
> >>
> >> To compare the first row:
> >>
> >> <?php
> >>
> >> $handle = fopen('file.csv', 'r') or die("unable to open file");
> >>
> >> $my_row = array('1','2','John Smith');
> >>
> >> $data = fgetcsv($handle, 1000, ",");
> >>
> >> if ($data === false) {
> >> 	echo "Unable to get anything from the file.";
> >> }
> >>
> >> if (is_array($data)) {
> >> 	if ($data == $my_row) {
> >> 		echo "The first row matched\n";
> >> 	} else {
> >> 		echo "The first row didnt match\n";
> >> 	}
> >> }
> >>
> >> fclose($handle);
> >>
> >>
> >> If you really do want to compare the first column, then the time to
> >> do
> >> it will be based on how big the csv file is. If you have a big file,
> >> it's going to take a long time to go through each row and then look
> >> at
> >> the first field.
> >>
> >> <?php
> >>
> >> $handle = fopen('file.csv', 'r') or die("unable to open file");
> >>
> >> $my_value = '1';
> >>
> >> $row_count = 0;
> >> while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
> >> 	$row_count++;
> >> 	if ($data[0] == $my_value) {
> >> 		echo "Found my_value on row ", $row_count, "\n";
> >> 	} else {
> >> 		echo "Did not find my_value on row ", $row_count, "\n";
> >> 	}
> >> }
> >>
> >> fclose($handle);
> >>
> >> --
> >> Postgresql & php tutorials
> >> http://www.designmagick.com/
> >>
> >
> >
> > --
> > This message has been scanned for viruses and
> > dangerous content by MailScanner, and is
> > believed to be clean.
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
> 
> 
> -- 
> Some people have a "gift" link here.
> Know what I want?
> I want you to buy a CD from some indie artist.
> http://cdbaby.com/from/lynch
> Yeah, I get a buck. So?
> 
> 


-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux