Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8840565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:29:33+00:00 2026-06-14T10:29:33+00:00

Following is the sample of my CSV file: Name | USD ———— Ifone |

  • 0

Following is the sample of my CSV file:

Name  | USD
------------
Ifone | 500
Ufone | 600

I want to read my csv file where my php script reads the first row and then (How to) create table accordingly as per the elements of the first row being returned like from the above example the row elements will be Name and USD.

Create table csv
{
$column1 varchar (50)
$column2 varchar (50)
}

Then (How to) store the elements starting from the 2nd row and so on in the created table. Kindly let me know what is an appropriate way to do that.

Thanks,

Following function I used to get data from my csv file:

$row = 1;
if (($handle = fopen("mycsv.csv", "r")) !== FALSE) {
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
        $num = count($data);
        echo "<p> $num fields in line $row: <br /></p>\n";
        $row++;
        for ($c=0; $c < $num; $c++) {
            echo $data[$c] . "<br />\n";
        }
    }
    fclose($handle);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T10:29:34+00:00Added an answer on June 14, 2026 at 10:29 am

    A better approach would be to:

    1) Study the CSV table format and decide on fields names and type, in your case e.g.

    fonemodel varchar(50);
    cost      integer;      -- or a monetary field
    

    2) Create the table manually from the fields above

    CREATE TABLE fones ...
    

    3) Import directly the file:

    LOAD DATA LOCAL INFILE '/path/to/mycsv.csv'
    INTO TABLE fones
    FIELDS TERMINATED BY ','
    ENCLOSED BY '"'
    LINES TERMINATED BY '\n'
    IGNORE 1 LINES
    

    The termination and enclosure depends on the CSV structure (the sample you supplied is actually pipe delimited).

    Once you have the two tables stored, you can run comparisons between the appropriate data types (varchar might have given you troubles – 599 could be considered to be less than 60, since the character ‘5’ comes before the ‘6’)

    Update

    Suppose that the real CSV is something like

     UFone,500,useless data,1234,other useless info,blah blah
    

    and you only wanted model, cost, and stock, i.e. columns 1, 2 and 4. Then you’d specify the input as:

     ...INTO TABLE fones (model, cost, @ignore, stock, @ignore, @ignore)...
    

    instead of simply INTO TABLE.

    More information on MySQL’s manual page.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following sample CSV file rc,u,s,ui,gh m,1,8,0,12 n,3,0,0,7 d,1,1,8,0 I want to read
I have a csv file with following sample data. o-option(alphabetical) v-value(numerical) number1,o1,v1,o2,v2,o3,v3,o4,v4,o5,v5,o6,v6 number2,o1,v11,o2,v22,o3,v33,o44,v44,o5,v55,o6,v66 and
I want to read a CSV file's columns directly into variables. The result should
I am using the following code to read in a CSV file: String next[]
I have the following sample code which doesn't seem to want to run. import
I have the following sample data: Id Name Quantity 1 Red 1 2 Red
I want to get 'second' in the following sample web address. http://www.mywebsite.com/first/sedond/third.html first can
I am dealing with a csv file that has some customer information (email, name,
I have written a simple perl script to read a line from a .csv
I have a simple .csv file that has that I want to extract data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.