Solved

MySQL - update columns values in table using MySQL or PHP

Posted on 2014-04-08
2
569 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 500 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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

740 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