Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Importing CSV file

Status
Not open for further replies.

Sarky78

Programmer
Joined
Oct 19, 2000
Messages
878
Location
GB
Hi,

Right I know there is a function called fgetcsv that I can use to read a csv file into an array, so thats not the problem.

What I have got is a row of headers, that name each of the fields in the CSV file. What I want to be able to do is to refer to the fields as these names if possible

For instance this is my code now:

while($data = fgetcsv ($fp, 1024, ",")) {
$CompanyName = AddSlashes(Trim($data[1]));
}

As I have got the field names at the top of the file, I would like to be able to refer to the fields using the names supplied like this:

while($data = fgetcsv ($fp, 1024, ",")) {
$CompanyName = AddSlashes(Trim($data["CompanyName"]));
}

I have seen most of the suggestions about importing it using the mySQL command LOAD Data, but I want to be able to assign the information coming in to the logged in user, and be able to split the data across various tables.

Is this possible?

Tony
 
nope that cannot be done. the array that is returned is given by fgetcsv.. but if u want something like that build ur own function... its easy...

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top