TechTalkz.com Logo

Go Back   TechTalkz.com Technology & Computer Troubleshooting Forums > Tech Support Archives > Programing Languages > PHP

Notices

fopen() and fgetcsv()

PHP


Reply
 
Thread Tools Display Modes
Old 07-12-2007, 05:08 PM   #1
mantrid
Guest
 
Posts: n/a
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
Old 07-12-2007, 05:08 PM   #2
Michael
Guest
 
Posts: n/a
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
Old 07-12-2007, 06:58 PM   #3
Olaf Schinkel
Guest
 
Posts: n/a
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
Old 07-12-2007, 06:58 PM   #4
C.
Guest
 
Posts: n/a
Re: fopen() and fgetcsv()

On 7 Dec, 13:05, Olaf Schinkel <> 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
Old 08-12-2007, 01:03 AM   #5
mantrid
Guest
 
Posts: n/a
Re: fopen() and fgetcsv()

thank you everyone

"mantrid" <> wrote in message
news:YYY5j.2742$.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



< Windows Help - MS Office Help - Hardware Support >


New To Site? Need Help?

All times are GMT +5.5. The time now is 07:06 AM.


vBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO
Copyright © 2005-2009, TechTalkz.com. All Rights Reserved - Privacy Policy
Valid XHTML 1.0 Transitional