How to update multiple lines in mysql?

Asked

Viewed 14 times

1

I have a table (respostas) MYSQL thus:

ID|resposta
1 | A
2 | B
3 | B
4 | C

Then when sending the form below it should update the response column according to the value of each input:

<form method="post">
 <input name="1">
 <input name="2">
 <input name="3">
 <input name="4">
</form>

There I do not know how to mount the query to bind the tables. What I thought is to make several updates, but I believe that there should be a simpler way.

In the form below, it would actually be generated by a foreach:

UPDATE repostas SET resposta = "$_POST['1']" WHERE id = 1
UPDATE repostas SET resposta = "$_POST['2']" WHERE id = 2
UPDATE repostas SET resposta = "$_POST['3']" WHERE id = 3
UPDATE repostas SET resposta = "$_POST['4']" WHERE id = 4
  • Voce has already created the foreach or just cited it in the question as an example ?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.