1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

import xml to mysql database using php

Discussion in 'PHP' started by maddest_lover, Nov 9, 2007.

Thread Status:
Not open for further replies.
  1. #1
    Dear all
    i am having a mysql database which is fed with a php form. i want to add an additional featute to the form: enter the data in mysql database using an xml file.

    The XML file may contain 1-10,000 enteries and each entry should form a unique entry in the mysql database. Please help me how can i
    1) enter the xml data directly into the mysql db
    2) Enter data from XML file using a php form.

    Any of the methods to enter the data are welcome.

    I am attaching a sample XML file which contains a number of enteries. Each entry starts with <PubmedArticle> tag and ends with </PubmedArticle> tag.

    Thanks in advance.
     

    Attached Files:

    maddest_lover, Nov 9, 2007 IP
  2. kmap

    kmap Well-Known Member

    Messages:
    2,215
    Likes Received:
    29
    Best Answers:
    2
    Trophy Points:
    135
    #2
    I can do this project for $200 by paypal

    Regards

    Alex
     
    kmap, Nov 9, 2007 IP
  3. lowridertj

    lowridertj Well-Known Member

    Messages:
    2,882
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    195
    #3
    the data must be parsed into an array 1 by 1 and entered threw a sequence into the database.

    Are you wanting the code in which will do this? or just how its done?
     
    lowridertj, Nov 9, 2007 IP
    maddest_lover likes this.
  4. maddest_lover

    maddest_lover Guest

    Messages:
    1,110
    Likes Received:
    39
    Best Answers:
    0
    Trophy Points:
    0
    #4
    yeah! thats going to be a great favour. Plz let me know the code to do it or a sample script.

    Thanks in advance.
     
    maddest_lover, Nov 10, 2007 IP
  5. lowridertj

    lowridertj Well-Known Member

    Messages:
    2,882
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    195
    #5
    
    
    <?php
    
    $insideitem = false;
    $tag = "";
    $title = "";
    $description = "";
    $link = "";
    
    function startElement($parser, $name, $attrs) {
    global $insideitem, $tag, $title, $description, $link;
    if ($insideitem) {
    $tag = $name;
    } elseif ($name == "ITEM") {
    $insideitem = true;
    }
    }
    
    function endElement($parser, $name) {
    global $insideitem, $tag, $title, $description, $link;
    if ($name == "ITEM") {
    printf("<dt><b><a href='%s'>%s</a></b></dt>",
    trim($link),htmlspecialchars(trim($title)));
    printf("<dd>%s</dd>",htmlspecialchars(trim($description)));
    $title = "";
    $description = "";
    $link = "";
    $insideitem = false;
    }
    }
    
    function characterdata($parser, $data) {
    global $insideitem, $tag, $title, $description, $link;
    if ($insideitem) {
    switch ($tag) {
    case "TITLE":
    $title .= $data;
    break;
    case "DESCRIPTION":
    $description .= $data;
    
    break;
    case "LINK":
    $link .= $data;
    break;
    }
    }
    }
    
    $xml_parser = xml_parser_create();
    xml_set_element_handler($xml_parser, "startElement", "endElement");
    xml_set_character_data_handler($xml_parser, "characterdata");
    $fp = fopen("*********","r")
    or die("Error reading RSS data.");
    while ($data = fread($fp, 4096))
    xml_parse($xml_parser, $data, feof($fp))
    or die(sprintf("xml error: %s at line %d",
    xml_error_string(xml_get_error_code($xml_parser)),
    xml_get_current_line_number($xml_parser)));
    fclose($fp);
    xml_parser_free($xml_parser);
    
    ?> 
    
    
    PHP:
     
    lowridertj, Nov 10, 2007 IP
  6. maddest_lover

    maddest_lover Guest

    Messages:
    1,110
    Likes Received:
    39
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thanks a lot lowridertj.

    I will use it n will tell u the results soon. Hope I will be fine with your code.

    Cheers.
     
    maddest_lover, Nov 10, 2007 IP
Thread Status:
Not open for further replies.