Skip to content
Advertisement

How to update a table with a foreach without overwriting?

So i’m working on a university project but i have a problem that’s really starting to bother me. I am trying to update my database several times with different values, except that only the last value will be taken into account : they’re overwriting themselves.

My code :

JavaScript
JavaScript

And my SQL method is like this :

JavaScript

So for example if I (id_demande = 1) choose 4 new structures with their id_structure : 22,23,24,25, I’m going to have my table who looks like :

ID_DEMANDE ID_STRUCTURE PRINCIPALE
1 25 0
1 25 0
1 25 0
1 25 0

Please does anyone know what to modify in my code so that my table looks like this after my update?

ID_DEMANDE ID_STRUCTURE PRINCIPALE
1 22 0
1 23 0
1 24 0
1 25 0

Thank you very much!

Advertisement

Answer

Thanks for all of your answers, as I’m running out of time, I decided to choose @ADyson’s solution :

Instead of doing like this :

JavaScript

I did this :

JavaScript

I’ll come back to you if I have time to set up a more dynamic version!

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement