Skip to content
Advertisement

foreach array wise multi SQL query not working in PHP

I am trying to execute multiple queries with the multiple selected checkbox value-wise in PHP. I am facing trouble that my code is executing only one checkbox value-wise query and the rest is denied.

I checked on StackOverflow about this issue and I got lots of threads about foreach loop but in my case, it is not working when I am applying that.

Please help me, I am first time trying the foreach loop and so that I have a bit confusing about the same. I have also the problem that I am not able not to validate invalid data through an array. How I fix this? it only works for the first check value but I want all checked checkboxes. I am trying to fetch data from the database of those particular ids which value I selected in the checkbox. and echo it in the array for that all query as I mention below-

Sending Form Data format as seen in dev tool

JavaScript

PHP

JavaScript

Advertisement

Answer

Try this, when using exit() inside the foreach the code does not continue and only performs the first element.

EDIT 1:

Ok, I’m going to explain a little more in depth how to optimize this code.

You get “id” identifiers from checked checkboxes.

You can use SQL IN () to optimize this.

Look at this

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