4

I have a table called tbl_portfolio described as below and i want to modify all imagePath columns by adding projectId at start, i.e abc.jpg will change to <project_id>/abc.jpg.I am not very skilled with Mysql.. :(

| portfolioId | int(11)      | NO   | PRI | NULL    | auto_increment |
| projectId   | int(11)      | YES  |     | NULL    |                |
| customerId  | int(11)      | YES  |     | NULL    |                |
| imagePath   | varchar(500) | YES  |     | NULL    |                |
| description | text         | YES  |     | NULL    |                |
| addDate     | date         | YES  |     | NULL    |                |
| lastUpdated | date         | YES  |     | NULL    |                |
| coverPhoto  | int(1)       | YES  |     | 0       |                |

7 Answers 7

4

Try this:

Use CONCAT function to merge the string

UPDATE tbl_portfolio 
SET imagePath = CONCAT(CAST(projectId AS CHAR(20)), '/', imagePath);
Sign up to request clarification or add additional context in comments.

Comments

0

Try this without where clause its update all rows. read this for more http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_concat

UPDATE tablename 
set imagePath = CONCAT(CAST(projectId AS CHAR(20)),"/",imagePath)

Comments

0

I think this will help

UPDATE tbl_portfolio SET imagePath = CONCAT('/', projectId);

Comments

0

You can include column values to another columns value. See simple example:

UPDATE tbl_portfolio SET imagePath = tbl_portfolio.projectId + '/' + tbl_portfolio.imagePath;

Comments

0

Please You are use Update Query.

<?php
  $Query= UPDATE tbl_portfolio SET imagePath='/abc.jpg' WHERE portfolioId=1;
  mysql_query ($Query);

?>

Comments

0
UPDATE tbl_portfolio
SET imagePath = CONCAT(projectId,"/",imagePath);

Comments

-2

you can use udate table command, the exact syntax will be like -

UPDATE tbl_portfolio SET imagePath='/abc.jpg';

more infoe here - http://dev.mysql.com/doc/refman/5.0/en/update.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.