Results 1 to 7 of 7

Thread: Import Data into mySQL

  1. #1
    Join Date
    Aug 2005
    Posts
    174
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Import Data into mySQL

    Hey,
    I want to automatically update (using a php script) a mySQL database using pipeline ( | ) seperated data from a webpage provided by an affiliate.

    Here's some example data from the webpage (feed.asp):

    Handset | Make | ID | date | features | description |
    Nokia N92 | Nokia | n92 | 999 | f,c,v,m,b,,g | The Nokia...... |

    Does anyone know how this can be done?

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    ob_start();
    include("http://www.affiliate.com/feed.asp");
    $feed = ob_get_contents();
    ob_end_clean();
    $heads = explode("\n", $feed);
    $data = explode("|", $feed[1]);
    $heads = explode("|", $feed[0]);
    for($i=0;$i<count($heads);$i++) {
      // Insert data into table - $heads[$i] and $data[$i]
    }
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Aug 2005
    Posts
    174
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    Thanks Twey,

    how would i insert that into a table?!

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    See the MySQL INSERT statement.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Aug 2005
    Posts
    174
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    Something like this?!?!?!

    PHP Code:
    mysql_query(INSERT INTO $table VALUES ($heads[$i],$data[$i])); 

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    No, you'd need to use the for loop to construct the query then execute it outside.
    PHP Code:
    $query "INSERT INTO $table VALUES (";
    for(
    $i=0;$i<count($heads);$i++)
      
    $query .= $data[$i] . ( $i count($heads) ? "," "" );
    $query .= ");";
    mysql_query($query); 
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Aug 2005
    Posts
    174
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    Twey, this is what i have so far..

    PHP Code:
    <?
    ob_start
    ();
    include(
    "http://www.mysite.com/feed.html");
    $feed ob_get_contents();
    ob_end_clean();
    $heads explode("\n"$feed);
    $data explode("|"$feed[1]);
    $heads explode("|"$feed[0]);
    for(
    $i=0;$i<count($heads);$i++) {
    $username="user";
    $password="pass";
    $database="database";
    $table="table";
    mysql_connect(localhost,$username,$password);
    @
    mysql_select_db($database) or die( "Unable to select database");
    $query "INSERT INTO $table VALUES (";
    for(
    $i=0;$i<count($heads);$i++)
    $query .= $data[$i] . ( $i count($heads) ? "," "" );
    $query .= ");";
    mysql_query($query);
    }
    ?>
    It just doesnt seem to add anything onto the database

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •