Results 1 to 3 of 3
  1. #1
    Join Date
    February 8th, 2008
    This Is My Multiple Datafeed Update Script... Help or Hinderance
    I'm sharing this for the simple fact that it might be very useful to someone out there, but also I feel it could be a lot simpler and therefore would relish honest critique (but only with alternative suggestions! lol).

    My website uses 17 different datafeeds to update my database. some of the different merchants stock the same products, so for the sake of helping you follow the script - initially when I started out filling my db i issued each individual product with a unique "sku".

    i manually enter beforehand by way of an simple php insert form the:

    brand // brand of the product
    brandID // the unique ID for that brand
    name // the name of the product in my format
    cat // the header category for which the product relates to
    sub // the sub category for which the product relates to
    mId // the merchant id from the datafeed
    pId // the product id from the datafeed


    brand // Christian Dior
    brandID // 152
    name // Fahrenheit Aftershave 50ml
    cat // 10 (represents "Fragrance" in my database)
    sub // 12 (represents "Aftershave" in my database)

    ...otherwise the script will not pick up that it needs to update the particular row in my database. this does slow me down, but it allows for me to have control over these specific elements of my database so i can eliminate duplicates and style the elements the way i want.

    so essentially while the script runs each individual line of the datafeed, if the mId and the pId match a row in my database, it knows then to update that particular row in my database with the information in the datafeed. Simple? Sort of...

      $offline = 'no'; // simple trigger that allows me to simply switch the merchant feed between active and not active
    mysql_query("UPDATE products SET forSale='no',inStock='no' WHERE mId='911'"); // default all products with that merchant ID to not in stock and not for sale
    if ($offline == 'no') { $xml = simplexml_load_file('**********************'); // in other words if my trigger variable $offline is marked to 'no' (not offline), run the update script
    foreach ($xml->xpath('//merch') as $character) {
      $mName = $character["mName"]; }
    foreach ($xml->xpath('//prod') as $character) { // run the datafeed
      $awId = $character["awId"];
      $pId = $character->pId;
      $desc = $character->desc;
      $desc = mysql_real_escape_string($desc); // some merchants are notorious for including descriptions with forbidden characters such as inverted commas or ampersand signs, so we escape it in order to avoid the script failing
      $awLink = $character->awLink;
      $delTime = $character->delTime;
      $delCost = $character->delCost;
      $search = $character->price->search; // this represents the price by the way
      $rrp = $character->price->rrp;
    mysql_query("UPDATE products SET
    inStock = 'yes', // don't forget - we've marked everything by this merchant as not in stock - so if it's on the feed, it's in stock!
    delTime='4 - 5 working days',
    WHERE mId='911' AND pId='$pId'") or die(mysql_error()); // we use the unique mId and pId which we have manually entered already to differentiate updating any other database entries with the same name and sku that are by different merchants. below we use the query to find these other products that are the same - defined by same sku - to find out which one is cheapest
      // DEFINE SKU
    $skuQuery=mysql_query("SELECT * FROM products WHERE pId='$pId'")or die(mysql_error());
    while($row = mysql_fetch_array( $skuQuery )) { $sku=$row[sku]; } // search for the entry by using the merchants unique pId and define the sku
      $i=10; // our starting point
    $saleQuery=mysql_query("SELECT * FROM products WHERE sku='$sku' AND inStock='yes' ORDER BY search,save DESC")or die(mysql_error()); // search for other products from the database that are in stock with their respective merchants and list them according to the cheapest and with the biggest saving on their rrp.
    while($row = mysql_fetch_array( $saleQuery )) {
        // DEFINE RRP
    if($i > '10'){ mysql_query("UPDATE products SET forSale='no',rrp='$rrp' WHERE sku='$sku' AND mId='$mId'"); } // if $i is bigger than our starting point, then we know that's not the cheapest - so mark as not for sale
    else { mysql_query("UPDATE products SET forSale='yes',rrp='$rrp' WHERE sku='$sku' AND mId='$mId'"); } $i++; } } // or else mark as for sale
    echo 'CheapSmells Online!<br />'; } // displays completion of script
    else { echo 'CheapSmells Offline!<br />'; } // if trigger was set to "yes" will display this message, having put every product with the merchant Id of 911 to out of stock and not for sale.
    i know that probably looks horrendous, particularly with my woeful commenting throughout the script, but it does work - though it may take up to 5 minutes to run and complete for a datafeed with approx 3000 entries.

    I'm very open to hearing how i could be doing this in a more efficient, quicker way.

  2. #2
    Join Date
    January 19th, 2009
    Have you tried requesting the file using gzip? This can reduce the size of the file by up to 75%...I was amazed with one script I was doing...file size went from 19k to 4.5k and I really noticed the increased speed.

  3. #3
    Join Date
    April 23rd, 2009
    Thx for sharing, this is exactly what I'm looking for.

  4. Newsletter Signup

+ Reply to Thread

Similar Threads

  1. Featured: Datafeed to SQL script? Not price comparison script
    By oxplode in forum Programming / Datafeeds / Tools
    Replies: 19
    Last Post: June 26th, 2014, 01:27 PM
  2. Need Programmer for FTP script, datafeed import script
    By markwelch in forum Programming / Datafeeds / Tools
    Replies: 10
    Last Post: April 20th, 2007, 01:16 PM
  3. Need Programmer for FTP script, datafeed import script
    By markwelch in forum Programming / Datafeeds / Tools
    Replies: 0
    Last Post: March 5th, 2007, 03:24 PM
  4. Script for multiple rate sites
    By ezkim0x in forum Programming / Datafeeds / Tools
    Replies: 5
    Last Post: September 13th, 2004, 12:11 AM

Posting Permissions

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