Solved

MySQL - update columns values in table using MySQL or PHP

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
php email 2 26
Php Email function not working with Template 8 38
can windows 10 wamp send mail()? 3 32
update joined tables 2 27
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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.

914 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

23 Experts available now in Live!

Get 1:1 Help Now