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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.