Return-Path: <php-db-return-30712-robert=seabreeze.asn.au@lists.php.net>
Envelope-To: robert@seabreeze.asn.au
X-Spam-Status: SpamAssassin Failed
Received: from pb1.pair.com ([216.92.131.4] verified)
  by hermajestystheatre.com.au (CommuniGate Pro SMTP 4.1.3)
  with SMTP id 353179 for robert@seabreeze.asn.au; Sat, 27 Sep 2003 03:14:13 +1000
Received: (qmail 35031 invoked by uid 1010); 26 Sep 2003 17:24:23 -0000
Mailing-List: contact php-db-help@lists.php.net; run by ezmlm
Precedence: bulk
list-help: <mailto:php-db-help@lists.php.net>
list-unsubscribe: <mailto:php-db-unsubscribe@lists.php.net>
list-post: <mailto:php-db@lists.php.net>
Delivered-To: mailing list php-db@lists.php.net
Received: (qmail 35018 invoked by uid 1010); 26 Sep 2003 17:24:23 -0000
Delivered-To: ezmlm-scan-php-db@lists.php.net
Delivered-To: ezmlm-php-db@lists.php.net
Message-ID: <20030926172422.1911.qmail@web20506.mail.yahoo.com>
Date: Fri, 26 Sep 2003 10:24:22 -0700 (PDT)
From: Karen Resplendo <karenresplendo@yahoo.com>
To: php-db@lists.php.net
In-Reply-To: <200309270115.42457.php-db@gremlins.biz>
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary="0-2001950533-1064597062=:1745"
Subject: Re: [PHP-DB] fgetcsv() only returns half of the rows

--0-2001950533-1064597062=:1745
Content-Type: text/plain; charset=us-ascii

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 <php-db@gremlins.biz> 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
--0-2001950533-1064597062=:1745--
