Zen Cart Logo
Forums / General Questions / How to use a append query to update all product descriptions?

How to use a append query to update all product descriptions?

Views: 1,250

Results 1 to 8 of 8
23 Aug 2016, 3:56 PM
#1
welshop_com avatar

welshop_com

Zen Follower

Join Date:
Aug 2004
Location:
Newport, Wales
Posts:
262
Plugin Contributions:
0

How to use a append query to update all product descriptions?

Hi
I would like to add a couple of lines of code to the beginning of every product description on my website celtmyth.co.uk and figured the easiest way after quick updates would be to use an append query but everything I have done has failed so far. (I use the Trial & Error query technique :smile: )

I tried
UPDATE zen_products_description(products_description, <h4>Special gifts for special occasions</h4> <h1>the details</h1>)

as well as

INSERT INTO zen_products_description(products_description) VALUES ([<h4>Special gifts for special occasions</h4> <h1>the details</h1>])

Neither worked so any help would be appreciated.

Cheers
Brinley

23 Aug 2016, 8:38 PM
#2
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,094
Plugin Contributions:
56

Re: How to use a append query to update all product descriptions?

How about a different solution to the problem?

Rather than adding that text to all products' descriptions, why not just update your (presumed, since you're using a URL rewriter) template's tpl_product_info_display.php file to include that common-to-all-products lead-in?

23 Aug 2016, 9:19 PM
#3
welshop_com avatar

welshop_com

Zen Follower

Join Date:
Aug 2004
Location:
Newport, Wales
Posts:
262
Plugin Contributions:
0

Re: How to use a append query to update all product descriptions?

Hi lat9

Rather a good idea - and I may eventually take that route if I cant get the query option to work.

But the query is my preference purely because I would now like to see if I can get it to work :D

Cheers
Brinley

23 Aug 2016, 10:22 PM
#4
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,094
Plugin Contributions:
56

Re: How to use a append query to update all product descriptions?

welshop.com:

Hi lat9

Rather a good idea - and I may eventually take that route if I cant get the query option to work.

But the query is my preference purely because I would now like to see if I can get it to work :D

Cheers
Brinley
OK, Brinley, based on this stackoverflow posting, you'd enter the following into your admin's Tools->Install SQL Patches (after backing up your database!):

UPDATE products_description SET products_description=CONCAT('<h4>Special gifts for special occasions</h4> <h1>the details</h1>',products_description);

That will prepend the HTML you identified into each product's description.

24 Aug 2016, 7:27 AM
#5
welshop_com avatar

welshop_com

Zen Follower

Join Date:
Aug 2004
Location:
Newport, Wales
Posts:
262
Plugin Contributions:
0

Re: How to use a append query to update all product descriptions?

Hi lat9

Thanks for the help - I did read quite a few threads on Stackoverflow and did see one on using CONCAT but didn't really understand it so i used append instead.

Will try it out later.

Thanks once again.

Cheers
Brinley

24 Aug 2016, 10:18 AM
#6
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: How to use a append query to update all product descriptions?

welshop.com:

Hi lat9

Thanks for the help - I did read quite a few threads on Stackoverflow and did see one on using CONCAT but didn't really understand it so i used append instead.

Will try it out later.

Thanks once again.

Cheers
Brinley

Not entirely sure if there is still a quest to find a way to append data to an existing field by any means other than the use of CONCAT (in applications such as Microsoft Excel or Open Office this would be CONCATENATE) or not. I've done some searching and it makes me think that the concept of an append query is/was being misunderstood. In other applications (the "popular" one on the Internet is Microsoft Access) an append query adds the records (rows) of data from one table to another. This is not the same as addding the field of one table (even if the table being temporary or permanent had only one record which was the data to be merged to the existing table) to the field of another.

Maybe once the above is attempted the success of its use can be identified.

Further, understanding the "need" to solve the problem to which the above solution was provided, be sure to consider the bigger picture like, now that this has been done with existing data, what is going to be done in the future to ensure that the exact same data will be prepended in the future? Why is the exact same data referenced? Well, consider further down the line when it is desired to change that statement? The only "convenient" way is to run another sql/search and modify the data one-for-one...

From a database container perspective, now every record contains the same data. This is instead of a single record of some type (suggested was a non-database style reference) that takes up less storage space or as suggested no database storage space at all.

There's nothing technically wrong about the approach, but remember that with every change or desired action, there is or will be maintenance involved. May not seem so now, but obviously there was something not liked about how it was, likely to be a similar dissatisfaction in the future.

Nothing wrong with trying to get to the bottom of an issue and trying to get one's questions answered. :)

24 Aug 2016, 11:01 AM
#7
welshop_com avatar

welshop_com

Zen Follower

Join Date:
Aug 2004
Location:
Newport, Wales
Posts:
262
Plugin Contributions:
0

Re: How to use a append query to update all product descriptions?

I have just run the query and can confirm it works perfectly - thx lat9 ur a star!

mc12345678 I understand the drawbacks you highlight but given that he length of the appended string is really small I don't think its an issue. I did look at creating a single addition to the product info page but decided I felt more comfortable with trying the query route.
As for the need make changes in the future - luckily I already know how to run a replace query :D

Thanks again for the input both- much appreciated.

Cheers
Brinley

24 Aug 2016, 11:33 AM
#8
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,094
Plugin Contributions:
56

Re: How to use a append query to update all product descriptions?

Happy to have helped, Brinley.