how to import data from excel to mysql using PHP?

Discussion in 'PHP' started by osho3, Jun 5, 2010.

  1. #1
    how to import data from excel to mysql using PHP?
     
    osho3, Jun 5, 2010 IP
  2. Scripts man

    Scripts man Guest

    Messages:
    51
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
  3. adamsinfo

    adamsinfo Greenhorn

    Messages:
    60
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    18
    #3
    Export data from excel to CSV, i.e.
    a1,a2,a3,a4
    b1,b2,b3,b4

    Then:
    $data = file_get_contents("./file");
    $lines = explode("\n", $data);
    $num = count($lines); //number of lines
    $ctr = 0;
    while ($ctr < $num)
    {
    $line = explode(",", $lines[$ctr]);
    $num2 = count($line);
    $ctr2 = 0;
    while ($ctr2 < $num2)
    {
    echo $line[$ctr2]; //this is your field
    $ctr2++;
    }
    $ctr++;
    }
     
    adamsinfo, Jun 5, 2010 IP
  4. qrpike

    qrpike Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    PEAR has a good package you can install, Excel_Spreadsheet_Reader.

    Used it on a project and it worked flawless.

    - Scripteen.com
     
    qrpike, Jun 6, 2010 IP
  5. Layoutzzz

    Layoutzzz Greenhorn

    Messages:
    78
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    18
    #5
    Hi,
    It is only example
     
    Last edited: Jun 6, 2010
    Layoutzzz, Jun 6, 2010 IP