473,378 Members | 1,309 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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
Dec 6 '07 #1
5 3164
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Joe Randstein | last post by:
Hi! I get CSV-data from a post-request. How can I work on that? Currently I save the data to a temp-file, then read it back with fgetcsv and then delete the temp-file. That works, but I don't...
7
by: git_cs | last post by:
Hey, guys and gals Somedays ago, I had asked for the DES algorithm in C language. Although I have written the algorthim in C myself, I am facing a peculiar problem, which I hope some of u guys and...
13
by: Blue | last post by:
Hi , Can any one please let me explain me the diffrences between "open"/ "fopen" or "read"/"fread" or "write/fwrite". I know that "open" /"read" / "write" are system calls and "fopen"...
2
by: Stephen Preston | last post by:
I have an xls worksheet I wish to export as a text or csv file to import with fgetcsv() The 'save as' function on excell lets me save as a comma separated value or tab delimited text files....
10
by: Julia | last post by:
Hi, there, I am trying to append a binary file by using: FILE *strean; stream = fopen( "c:\temp.dat", "ba+" )); Is there a way that I can check if the file exists or not before fopen,...
0
by: et | last post by:
fgetcsv() do unwanted "left trim" on fields started with locale characters (code page win-1250). Problem persist only if local character is first character in field for example, let say that C...
3
by: siyaverma | last post by:
i am trying to upload csv file from user's computer to main server the code i am using is if(((isset($_GET)) && ($_GET=="yes")) ) { $typefield = $_GET; echo...
3
by: jrrdnx | last post by:
I have a form set up to allow someone to upload a .csv and populate its data into a database using the fgetcsv() function. All of the code works fine because everything in the .csv file is populated...
2
code green
by: code green | last post by:
I am trying to skip empty rows in a csv file The manual states But none of these tests seem to work. Anybody know why while(($data = fgetcsv($this->handle)) !== false) { ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.