Assume that the member information is retrieved from the database
The member has a field, assuming it is called p
The p of each member will have a value
I want to make a project where I can "get the p of all members at once Modify the value"
How should I handle my php backend? !
First write an array to store the member ID and modify the p value
The solution currently adopted by @tony_yin is the most basic solution. In actual applications, attention should be paid to enabling the transaction before the for loop starts and submitting the transaction after it ends. Otherwise, not to mention low performance, if there is a problem with the program during the for loop, it is easy to cause only some of the users' p values to be updated, while the other parts are not.
I will add another solution here: since it is mysql, you can use
INSERT ... ON DUPLICATE KEY UPDATE
to batch update. Sample SQL:Find out the member’s ID and modify it once.
If the amount of data is large, process it in batches
It doesn’t matter if the amount of data is small and it can be placed in a loop
Depending on your own needs
I didn’t understand your question. Please describe it clearly when I ask. Otherwise it will be a rubbish question.
I think you want to ask some members to set their p fields at once, right?
`
update table set p = value where uid in(1,2,3)
`
Write the following where condition yourself according to the specific scenario
Or you’d better re-describe your problem