Re: [PHP] CSV file

2009-06-25 Thread Shawn McKenzie
Jonathan Tapicer wrote: > Hi, > > I don't say that reading the whole file into memory is the best > option, I just say that your approach goes to the disk twice, if you > have a 100MB file, you are reading 200MB from disk (unless there are > some pages cached in physical memory, but you never can

Re: [PHP] CSV file

2009-06-25 Thread Jonathan Tapicer
Hi, I don't say that reading the whole file into memory is the best option, I just say that your approach goes to the disk twice, if you have a 100MB file, you are reading 200MB from disk (unless there are some pages cached in physical memory, but you never can know, in the best case all the pages

Re: [PHP] CSV file

2009-06-25 Thread Richard Heyes
Hi, > Well, you are reading the whole file there (and throwing the data you > read not assigning the fgets result to anything), and then to store it > in the database you need to read it again, so you read the file twice. > It will probably better to store the data you read the first time in > an

Re: [PHP] CSV file

2009-06-24 Thread Jonathan Tapicer
Well, you are reading the whole file there (and throwing the data you read not assigning the fgets result to anything), and then to store it in the database you need to read it again, so you read the file twice. It will probably better to store the data you read the first time in an array and then

Re: [PHP] CSV file

2009-06-24 Thread Eddie Drapkin
or $arr = file('foo.csv'); $count = count($arr); On Wed, Jun 24, 2009 at 5:19 PM, Richard Heyes wrote: > Hi, > >> To do the line count first, you have to read the whole file, how would >> you do it? > > Something like this: > > $fp = fopen('/tmp/foo', 'r'); > $count = 0; > > while (!feof($fp)) { >

Re: [PHP] CSV file

2009-06-24 Thread Richard Heyes
Hi, > To do the line count first, you have to read the whole file, how would > you do it? Something like this: $fp = fopen('/tmp/foo', 'r'); $count = 0; while (!feof($fp)) { fgets($fp); ++$count; } -- Richard Heyes HTML5 graphing: RGraph (www.rgraph.net - updated 20th June) PHP mail: RMail

Re: [PHP] CSV file

2009-06-24 Thread Jonathan Tapicer
To do the line count first, you have to read the whole file, how would you do it? On Wed, Jun 24, 2009 at 3:00 PM, Richard Heyes wrote: > Hi, > >> If you want to know how many lines there are *before* inserting to the >> database, you can't count "as you go", you have to either read the >> file tw

Re: [PHP] CSV file

2009-06-24 Thread Richard Heyes
Hi, > If you want to know how many lines there are *before* inserting to the > database, you can't count "as you go", you have to either read the > file twice or read it once, store it memory in a variable and then > insert in the database. Sure you can, simply do the line count first, then the i

Re: [PHP] CSV file

2009-06-24 Thread Shawn McKenzie
Stuart wrote: > 2009/6/24 Jonathan Tapicer : >> If you want to know how many lines there are *before* inserting to the >> database, you can't count "as you go", you have to either read the >> file twice or read it once, store it memory in a variable and then >> insert in the database. > > Do it in

Re: [PHP] CSV file

2009-06-24 Thread Stuart
2009/6/24 Jonathan Tapicer : > If you want to know how many lines there are *before* inserting to the > database, you can't count "as you go", you have to either read the > file twice or read it once, store it memory in a variable and then > insert in the database. Do it in bytes rather than lines

Re: [PHP] CSV file

2009-06-24 Thread Jonathan Tapicer
If you want to know how many lines there are *before* inserting to the database, you can't count "as you go", you have to either read the file twice or read it once, store it memory in a variable and then insert in the database. On Wed, Jun 24, 2009 at 11:12 AM, Richard Heyes wrote: > Hi, > >> You

Re: [PHP] CSV file

2009-06-24 Thread Richard Heyes
Hi, > You can read the whole file (file_get_contents) and count the number > of "\n" in it, or read it line by line with fgets and store the lines > in an array, and then the number of lines is the count() of the array, > and you can use that array to store it in the database. If you have a billi

Re: [PHP] CSV file

2009-06-24 Thread Jonathan Tapicer
You can read the whole file (file_get_contents) and count the number of "\n" in it, or read it line by line with fgets and store the lines in an array, and then the number of lines is the count() of the array, and you can use that array to store it in the database. Jonathan On Wed, Jun 24, 2009 a

[PHP] CSV file

2009-06-24 Thread Alain Roger
Hi, i would like to import the content of a CSV file into my database. but in order to show a progress bar to user (to let him know that process is still working on) i would like to determine before to start, how many records / lines are in the CSV file. is there a way to do that ? thanks a lot.

Re: [PHP] CSV file with PHP

2003-10-10 Thread Curt Zirzow
On Fri, 10 Oct 2003 18:09:14 -0400, Dan Anderson <[EMAIL PROTECTED]> wrote: while ($line = mysql_fetch_array($result)) { if ($first) { foreach ($line as $key => $value) { if ($first) { fwrite($file_handle, $key); $first = FALSE; } else { fwrite($file_handle, ", $key"); } } fwrite ($file_handle

Re: [PHP] CSV file with PHP

2003-10-10 Thread Dan Anderson
You could do something like: $result = mysql_query($query) or die(mysql_error()); // don't display errors on production machines $first = TRUE; while ($line = mysql_fetch_array($result)) { if ($first) { foreach ($line as $key => $value) { if ($first) { fwrite($f

[PHP] CSV file with PHP

2003-10-10 Thread Cesar Aracena
Hi all, Does anybody knows how to make a CSV (comma separated values) file with PHP based on results fetched from MySQL? I need it to import it with Microsoft Outlook Express. Thanks in advanced, Cesar Aracena www.icaam.com.ar -- PHP General Mailing List (http://www.php.net/) To unsubscribe, v