Jump to content

[SOLVED] Getting CSV Column Names


PHPNewbie55

Recommended Posts

I am trying to create a CSV Import Script..

 

I can import and get the data into MySQL... no problem...

But I have to define everything in the script beforehand

 

What I am trying to do now is make it so that I can MAP any CSV file to my MySQL Database..

 

What I am having a problem with is getting the first row of the CSV file to get the NAMES of each CSV Column..

 

Here is how I am getting the MySQL Column Names::::

<?php
$get_columns = mysql_query("SELECT * FROM $mysqltbl");
while ($columns = mysql_fetch_field($get_columns)) {
$mysql_column_names .= "".$columns->name."<br>";
?>

That works...

 

But I can't seem to figure out how to do the same thing with the CSV file....

<?php
$CSV_File = "Test_data.csv";
$csv = fopen($CSV_File, 'r');

while ($data = fgetcsv ($csv, 10000, ",")) {
$csv_column_names .= "".$data->name."<br>";
}
?>

 

Any ideas how to just grab the column names in the csv file..??

Link to comment
https://forums.phpfreaks.com/topic/82406-solved-getting-csv-column-names/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.