0

I need to take the value in a table to generate a URL containing this value and insert it in a new table. Is it possible to use variables within MySQL to form this URL?

Example:

SELECT `identity_id`, `email` FROM `identities` WHERE 1

Output: 1 [email protected]

With the ID and email in hand, I need to insert the HTML content below where the respective email for each ID says VARIABLE.

INSERT INTO `identities`(`html_signature`) VALUES ([<img src="https://example.com/images/VARIABLE.png" width="580" height="138">])

Thanks for help

1 Answer 1

1

You can use the select into statement

INSERT INTO `identities` (`html_signatures`)
  SELECT CONCAT("<img src=\"https://example.com/images/", `email`, ".png\" width=\"580\" height=\"138\">") as html_signatures
  FROM `identities` WHERE 1

I'm not sure if VARIABLE represented the id, email, or both but you could change the concat function arguments as needed.

Sign up to request clarification or add additional context in comments.

2 Comments

Result: #1364 - Field 'user_id' doesn't have a default value
Is that error from MySQL or somewhere else?

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.