Re: [PHP-DB] fgetcsv() only returns half of the rows
On Friday 26 September 2003 23:46, Karen Resplendo wrote: There are 113 rows in my comma delimited text file and the code below only displays 62 of them. It executes very quickly so I'm not thinking there is a time out problem. Any ideas? //here is URL with fgetcsv() explanation: http://us3.php.net/manual/en/function.fgetcsv.php $uploadthis = 'C:/AsciiTestJohn/OR100012-09252003.txt'; $row = 1; $handle = fopen ($uploadthis,r); rewind($handle); while ($fieldarray = fgetcsv ($handle, 300, ,)) { $fieldcount = count ($fieldarray); print p $fieldcount fields in line $row: br\n; $row++; for ($c=0; $c $fieldcount; $c++) { print $fieldarray[$c] . br\n; } Your logic here seems a bit odd. In your WHILE clause you're reading chunks of 300 chars at a time. Then in the code below, you're reading in another chunk of 300 chars. Thus each iteration of the WHILE-loop reads in 600 chars from the file. Is that your real intention? $buffer = fgets($handle,300); $buffer = str_replace(\,,$buffer); print $buffer.br; } //end of while loop fclose ($handle); -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-db -- /* ...there can be no public or private virtue unless the foundation of action is the practice of truth. - George Jacob Holyoake */ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] fgetcsv() only returns half of the rows
Does that mean that my length setting has to be exactly the length of the row? I don't know this because it is a comma delimited file, not a space delimited. The function description says: The length parameter must be greater than the longest line to be found in the CSV file (allowing for trailing line-end characters). I removed this block where I do an fgets() and then I get all rows displayed. Also, I was mistaken about total rows. There are 123 and I only display 62, which is half, so I'm thinking something is being incremented twice instead of once. What should I set the length at?: $buffer = fgets($handle,300); $buffer = str_replace(\,,$buffer); print $buffer.br; Jason Wong [EMAIL PROTECTED] wrote: On Friday 26 September 2003 23:46, Karen Resplendo wrote: There are 113 rows in my comma delimited text file and the code below only displays 62 of them. It executes very quickly so I'm not thinking there is a time out problem. Any ideas? //here is URL with fgetcsv() explanation: http://us3.php.net/manual/en/function.fgetcsv.php $uploadthis = 'C:/AsciiTestJohn/OR100012-09252003.txt'; $row = 1; $handle = fopen ($uploadthis,r); rewind($handle); while ($fieldarray = fgetcsv ($handle, 300, ,)) { $fieldcount = count ($fieldarray); print $fieldcount fields in line $row: \n; $row++; for ($c=0; $c $fieldcount; $c++) { print $fieldarray[$c] . \n; } Your logic here seems a bit odd. In your WHILE clause you're reading chunks of 300 chars at a time. Then in the code below, you're reading in another chunk of 300 chars. Thus each iteration of the WHILE-loop reads in 600 chars from the file. Is that your real intention? $buffer = fgets($handle,300); $buffer = str_replace(\,,$buffer); print $buffer. ; } //end of while loop fclose ($handle); -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-db -- /* ...there can be no public or private virtue unless the foundation of action is the practice of truth. - George Jacob Holyoake */ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php - Do you Yahoo!? The New Yahoo! Shopping - with improved product search
Re: [PHP-DB] fgetcsv() only returns half of the rows
On Saturday 27 September 2003 01:24, Karen Resplendo wrote: Does that mean that my length setting has to be exactly the length of the row? No. I don't know this because it is a comma delimited file, not a space delimited. The function description says: The length parameter must be greater than the longest line to be found in the CSV file (allowing for trailing line-end characters). So set it to [max line length]+10. I removed this block where I do an fgets() and then I get all rows displayed. Also, I was mistaken about total rows. There are 123 and I only display 62, which is half, so I'm thinking something is being incremented twice instead of once. Exactly, that block of code below is reading in another line. What is it's purpose anyway? What are you trying to achieve? What should I set the length at?: $buffer = fgets($handle,300); $buffer = str_replace(\,,$buffer); print $buffer.br; -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-db -- /* The wise man seeks everything in himself; the ignorant man tries to get everything from somebody else. */ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] fgetcsv() only returns half of the rows
What I am trying to do: lab uploads txt file php validates file, row by row, field by field (against database) I display bad rows and reasons in red and reject file I've figured out a different way to display the whole row by just printing the array with , instead of br/n Just wondering why the row pointer was getting incremented and now I think I know why: a call to both fgetcsv() and fget() will each increment the row pointer by one. No? So, taking this out leaves only fgetcsv() to increment the rows in the text file it is looking at: /*$buffer = fgets($handle,300); $buffer = str_replace(\,,$buffer); print $buffer.br;*/ Warning: more on this later :) Jason Wong [EMAIL PROTECTED] wrote: On Saturday 27 September 2003 01:24, Karen Resplendo wrote: Does that mean that my length setting has to be exactly the length of the row? No. I don't know this because it is a comma delimited file, not a space delimited. The function description says: The length parameter must be greater than the longest line to be found in the CSV file (allowing for trailing line-end characters). So set it to [max line length]+10. I removed this block where I do an fgets() and then I get all rows displayed. Also, I was mistaken about total rows. There are 123 and I only display 62, which is half, so I'm thinking something is being incremented twice instead of once. Exactly, that block of code below is reading in another line. What is it's purpose anyway? What are you trying to achieve? What should I set the length at?: $buffer = fgets($handle,300); $buffer = str_replace(\,,$buffer); print $buffer. ; -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-db -- /* The wise man seeks everything in himself; the ignorant man tries to get everything from somebody else. */ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php - Do you Yahoo!? The New Yahoo! Shopping - with improved product search