Jump to content

[SOLVED] MySql concat query, and then trim query


quasiman

Recommended Posts

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>";
			        }
?>

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'  :confused:

<?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>";
                    }
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.