By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,375 Members | 3,001 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,375 IT Pros & Developers. It's quick & easy.

fopen() and fgetcsv()

P: n/a
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
Dec 6 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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
Dec 6 '07 #2

P: n/a
On Thu, 06 Dec 2007 21:29:44 +0100, mantrid <ia********@virgin.netwrote:
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?
By discarding the first row before the while loop?

$fh = fopen(...);
fgetcsv($fh);
while($row = fgetcsv($fh)){
//stuff...
}
--
Rik Wasmus
Dec 6 '07 #3

P: n/a
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
Dec 7 '07 #4

P: n/a
C.
On 7 Dec, 13:05, Olaf Schinkel <tr...@schinkel.tvwrote:
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.
Dec 7 '07 #5

P: n/a
thank you everyone

"mantrid" <ia********@virgin.netwrote in message
news:YY*****************@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


Dec 7 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.