Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Search and Replace in SQL


tetrad

Recommended Posts

Hey all,

 

I'm searching for some code examples or an exact way to go in to PHPmySQL and do a global replace of a keyword in the 'Products Description' section of the product page.

 

What I would like to do is replace, for example, the keywords 'mixing bowl', in every instance of the 'Products Description' of a category with a link to the items for sale in the mixing bowl category in another section of the site. So I would want to replace 'Mixing Bowl' with '<A href="http://cookingfor.us/catalog/baking-mixing-bowls-c-161_162_179.html">Mixing Bowl</A>'

 

Could someone point me to a code example or method on how to do keyword replacements like above in different categories?

 

Thank you, :thumbsup:

 

Sean Smith

The cookingfor.us Team

Link to comment
Share on other sites

You will will need to write a separate script that queries the database for all products that have a description that contains the keyword. Then replace the keyword replacement and update the appropriate record.

 

If you do not have a replacements to do then you could use PHPMyAdmin but if you have a large number of products it will take a while.

"Great spirits have always found violent opposition from mediocre minds. The latter cannot understand it when a man does not thoughtlessly submit to hereditary prejudices but honestly and courageously uses his intelligence." - A. Einstein

Link to comment
Share on other sites

you do:

 

update products_descrtiption set products_description = replace (products_description, 'Mixing Bowl', '<A href="http://cookingfor.us/catalog/baking-mixing-bowls-c-161_162_179.html">Mixing Bowl</A>');

Link to comment
Share on other sites

Mark's suggestion is the best but keep in mind that you will need to have MySQL v4.1 or better for it to work.

"Great spirits have always found violent opposition from mediocre minds. The latter cannot understand it when a man does not thoughtlessly submit to hereditary prejudices but honestly and courageously uses his intelligence." - A. Einstein

Link to comment
Share on other sites

Will this execute across the entire database? I have a few categories that I want to avoid putting the replacement links in. Is there a way to specifiy categories when I run the query?

 

Thank you very much for the code, btw.

 

you do:

 

update products_descrtiption set products_description = replace (products_description, 'Mixing Bowl', '<A href="http://cookingfor.us/catalog/baking-mixing-bowls-c-161_162_179.html">Mixing Bowl</A>');

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...