Solved

MySQL - update columns values in table using MySQL or PHP

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Encode a password 2 39
spacing 5 32
Codiing Non-Existent Links 4 30
Why does my array not "dump?" 5 20
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
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 …

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now