Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

MySQL - update columns values in table using MySQL or PHP

Posted on 2014-04-08
2
Medium Priority
?
575 Views
Last Modified: 2014-04-08
Hi,
I have a table with 5 image columns

image1, image2, image3, image4 & image5  
 
which have been copied from a previous record with id ='782' and contain the following values


/uploads/item_782_1.jpg
/uploads/cat_food_782_2.jpg
/uploads/cat_food_782_3.jpg
uploads/nopic.jpg
uploads/nopic.jpg

is there an easy way to change these values with the new record id of '1072' using either a MySQL satement or PHP?

/uploads/item_1072_1.jpg
/uploads/cat_food_1072_2.jpg
/uploads/cat_food_1072_3.jpg
uploads/nopic.jpg
uploads/nopic.jpg

Thanks
0
Comment
Question by:sabecs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 35

Accepted Solution

by:
Terry Woods earned 2000 total points
ID: 39987647
Perhaps something like this. I've assumed there will be an underscore on either side of the id in the filename:

update my_table
set image1 = REPLACE(image1, '_782_', '_1072_'),
image2 = REPLACE(image2, '_782_', '_1072_'),
image3 = REPLACE(image3, '_782_', '_1072_'),
image4 = REPLACE(image4, '_782_', '_1072_'),
image5 = REPLACE(image5, '_782_', '_1072_')
where id = 1072

Open in new window

0
 

Author Closing Comment

by:sabecs
ID: 39988020
Thanks Terry, that's perfect..
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question