?
Solved

MySQL - update columns values in table using MySQL or PHP

Posted on 2014-04-08
2
Medium Priority
?
572 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

WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
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

752 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