473,800 Members | 2,613 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3184
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********@vir gin.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********@vir gin.netwrote in message
news:YY******** *********@newsf e7-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
6361
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 really like it ... Is there a way to directly parse the CSV data from the string (with php-4.2.4) Thanks for your answers!
7
3038
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 gals solve. I use Turbo C++ version 3.0 and WINXP as the operating system. Pls observe the following program. 1 #include<stdio.h> 2 #include<conio.h>
13
22640
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" /"fread" / "fwrite" are normal library functions. May be internally must be calling "fopen" /"fread" / "fwrite" functions.
2
6246
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. Trouble is, some of my cells already have commas in them, so a tab or something else would be better. In the delimiter option of fgcsv(), can you specify a tab and how? My other option (but a bit of a chore) is to copy and paste the xls data into...
10
3966
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, because I will call different work flow by check the status of
0
1582
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 is locale character, and this is CSV file: BCB;CAAA fgetcsv(CSV file) fill array with:
3
22056
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 "<form enctype=\"multipart/form-data\" action=\"$PHP_SELF\" method=\"POST\">
3
3552
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 into the database just fine, except for the very last row of data. I have tried several different ways of using the fgetcsv(), including: while ($result = fgetcsv($handle)) { while (($result = fgetcsv($handle)) != false) { while (($result...
2
17155
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) { if(!is_null($data)) #no if(!empty($data)) #no if(!empty($data)) #no { And variations thereof
0
9691
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9551
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10279
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10255
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9092
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7582
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6815
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3765
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2948
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.