fopen() and fgetcsv()

This is a discussion on fopen() and fgetcsv() within the alt.comp.lang.php forums, part of the PHP Programming Forums category; I am using fopen() and fgetcsv() to open an excel file and extract data for upload to mysql database. The ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-06-2007
mantrid
 
Posts: n/a
Default fopen() and fgetcsv()

I am using fopen() and fgetcsv() to open an excel file and extract data for
upload to mysql database. The doesnt seem to be a parameter in either of
these functions for ommitting the first row of the excel file. I am
currently using While ...... statement to read the rows and do things with
them. Can I ommit the first line without replacing my 'While....' loop with
a 'For......' loop?

Ian


Reply With Quote
  #2 (permalink)  
Old 12-06-2007
Michael
 
Posts: n/a
Default Re: fopen() and fgetcsv()

mantrid wrote:
> I am using fopen() and fgetcsv() to open an excel file and extract data for
> upload to mysql database. The doesnt seem to be a parameter in either of
> these functions for ommitting the first row of the excel file. I am
> currently using While ...... statement to read the rows and do things with
> them. Can I ommit the first line without replacing my 'While....' loop with
> a 'For......' loop?
>
> Ian
>
>


Certainly, take your pick, both should work fine:

$i = 0;
while ($i++ && false !== $data = fgetcsv($fh, 1024)) {
if ($i == 1)
continue;
print_r($data);
}


$firstline = true;
while (false !== $data = fgetcsv($fh, 1024)) {
if ($firstline == true) {
$firstline = false;
continue;
}
print_r($data);
}


- Michael
Reply With Quote
  #3 (permalink)  
Old 12-07-2007
Olaf Schinkel
 
Posts: n/a
Default Re: fopen() and fgetcsv()

mantrid schrieb:
> I am using fopen() and fgetcsv() to open an excel file and extract data for
> upload to mysql database. The doesnt seem to be a parameter in either of
> these functions for ommitting the first row of the excel file. I am
> currently using While ...... statement to read the rows and do things with
> them. Can I ommit the first line without replacing my 'While....' loop with
> a 'For......' loop?
>
> Ian
>
>

Remove the first line....
$fh = fopen(...

fgets($fh); <- only insert this line into your code

while(...


Olaf
Reply With Quote
  #4 (permalink)  
Old 12-07-2007
C.
 
Posts: n/a
Default Re: fopen() and fgetcsv()

On 7 Dec, 13:05, Olaf Schinkel <tr...@schinkel.tv> wrote:
> mantrid schrieb:> I am using fopen() and fgetcsv() to open an excel file and extract data for
> > upload to mysql database. The doesnt seem to be a parameter in either of
> > these functions for ommitting the first row of the excel file. I am
> > currently using While ...... statement to read the rows and do things with
> > them. Can I ommit the first line without replacing my 'While....' loop with
> > a 'For......' loop?

>
> > Ian

>
> Remove the first line....
> $fh = fopen(...
>
> fgets($fh); <- only insert this line into your code
>
> while(...
>
> Olaf


I suspect if I suggested that validating the record with a regex
instead of using positional information might be more appropriate I'd
just confuse people. So I won't.

C.
Reply With Quote
  #5 (permalink)  
Old 12-07-2007
mantrid
 
Posts: n/a
Default Re: fopen() and fgetcsv()

thank you everyone

"mantrid" <ian.dandav@virgin.net> wrote in message
news:YYY5j.2742$1j1.2444@newsfe7-gui.ntli.net...
> I am using fopen() and fgetcsv() to open an excel file and extract data

for
> upload to mysql database. The doesnt seem to be a parameter in either of
> these functions for ommitting the first row of the excel file. I am
> currently using While ...... statement to read the rows and do things

with
> them. Can I ommit the first line without replacing my 'While....' loop

with
> a 'For......' loop?
>
> Ian
>
>



Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 06:02 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0