且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将多个复选框值插入数据库

更新时间:2022-12-11 20:28:03

考虑一下您的代码在做什么.在每个循环中,您都在重新定义$query变量,以便结束时,$query的最终值将是您最后一次检查的想法.

Think about what your code is doing. Each loop, you're redefining the $query variable, so that when you get to the end, the final value of $query will be the last think you checked.

如果您仍想使用与编写的循环逻辑相同的方法(这可能不是最有效的方法),则每次在 循环中都必须执行查询,因此您编写的每个查询都将被执行.

If you still want to use the same loop logic that you have written, which is probably not the most efficient way, then you'd have to execute the query each time within the loop, so that each query you write will be executed.

更确切地说,您似乎还没有发现分配变量值和将变量传递给函数执行之间的区别,这是造成混淆的原因.

More precisely, the confusion seems to be stemming from the fact you haven't quite discovered the difference between assigning a value to a variable and passing a variable to a function for execution.