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.

Insert only selection from XML datafeed into mysql?

Discussion in 'PHP' started by philb, Nov 28, 2011.

  1. #1
    Hello Guys

    I've been working with XML datafeeds and I have a feed that holds 3,000 products.

    However, I only want to use products from the feed with 'dahon' in the name. This is only about 12 of the 3,000.

    Can I modify my PHP to only insert the products with 'dahon' in the name?

    Here's my code I'm using...

    $xml = simplexml_load_file("foldingdatafeed_79329.xml");
    
    foreach($xml->merchant->prod as $product){
    $productid = $product->id;
    $name = $product->text->name;
    $descrip = $product->text->desc;
    
    
    $sql = "INSERT INTO products (productid, productname, productdescription)
    VALUES ('$productid', '$name', '$descrip')";
    PHP:
    Any help would be appreciated
     
    Solved! View solution.
    philb, Nov 28, 2011 IP
  2. #2
    $xml = simplexml_load_file("foldingdatafeed_79329.xml");

    foreach($xml->merchant->prod as $product){
    $productid = $product->id;
    $name = $product->text->name;
    $descrip = $product->text->desc;

    $pos = strpos($name,"dahon");

    if($pos === false) {

    }
    else
    {

    $sql = "INSERT INTO products (productid, productname, productdescription)
    VALUES ('$productid', '$name', '$descrip')";
    ...
    }
     
    kmap, Nov 28, 2011 IP
  3. philb

    philb Peon

    Messages:
    61
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Many Thanks Kmap :)
     
    philb, Nov 28, 2011 IP
  4. philb

    philb Peon

    Messages:
    61
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Can I ask one more thing.

    I'm having trouble inserting the merchant name and product id.

    The XML holding the info starts with them like this..

    <merchant id="1302" name="Evans Cycles">
    <prod id="32672061">
    <text><name>Pashley Princess Classic Hybrid bike</name>......................</prod>

    How can I define the merchant name and product id in the code I'm using.

    foreach($xml->merchant->prod as $product){
    $productid = $product->id;
    $name = $product->text->name;
    $descrip = $product->text->desc;
    PHP:
     
    philb, Nov 28, 2011 IP