quasiman Posted August 25, 2009 Share Posted August 25, 2009 My subject sucks, but I wasn't sure how else to sum it up lol Anyway, I have 2 data sources populating tables, and then after formatting the data I import it into my shop. I've come across an issue with this, in that there are duplicate sku identifiers. So I want to edit the sku's before importing into my shop, to make them unique. I want to throw this out for any suggestions on maybe a better way, or even if my CONCAT and LTRIM queries will work! FYI - $body is used for my email notification <?php /* database connection and email sending stuff here */ $query = "UPDATE zdata_w_data SET PartNumber = CONCAT('W-',PartNumber)"; $result = mysql_query($query) or die(mysql_error()); if (!$result) { die('Invalid query: ' . mysql_error()); } else { $body .= "<li>Updated incoming SKU's</li>"; $query = "jos_vm_product p,zdata_w_data wd SET p.product_sku = wd.PartNumber WHERE pr.product_sku = LTRIM('W-',wd.PartNumber)"; $result = mysql_query($query) or die(mysql_error()); if (!$result) { die('Invalid query: ' . mysql_error()); } else { $body .= "<li>Updated Shop SKU's</li>"; } ?> Quote Link to comment Share on other sites More sharing options...
quasiman Posted August 26, 2009 Author Share Posted August 26, 2009 bump...and some more info, I ran the script and it didn't work, so I edited it a bit and tried again...still didn't work. Here's the changed 2nd query, phpMyAdmin says 'Affected rows: 0' <?php /* database connection and email sending stuff here */ $query = "UPDATE zdata_w_data SET PartNumber = CONCAT('W-',PartNumber)"; $result = mysql_query($query) or die(mysql_error()); if (!$result) { die('Invalid query: ' . mysql_error()); } else { $body .= "<li>Updated incoming SKU's</li>"; $query = "UPDATE jos_vm_product p,zdata_w_data wd SET p.product_sku = wd.PartNumber WHERE p.product_sku = SUBSTRING(wd.PartNumber,1,2)"; // <---the change $result = mysql_query($query) or die(mysql_error()); if (!$result) { die('Invalid query: ' . mysql_error()); } else { $body .= "<li>Updated Shop SKU's</li>"; } ?> Quote Link to comment Share on other sites More sharing options...
ignace Posted August 26, 2009 Share Posted August 26, 2009 UPDATE jos_vm_product p,zdata_w_data wd SET p.product_sku = wd.PartNumber WHERE p.product_sku = SUBSTRING(wd.PartNumber,3) Quote Link to comment Share on other sites More sharing options...
quasiman Posted August 26, 2009 Author Share Posted August 26, 2009 SUBSTRING(wd.PartNumber,3) wow....I've been trying to figure this out all day!! Thank you! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.