Ok, i have a checklist system that i am working on. There is a page that pulls data from the database and displays it as a checklist. I am trying to create a button that when pushed will reset the database to a certain state that i want. Basically, i have a button that sends an ajax callout to a php page that executes an UPDATE query. This query is as follows:
UPDATE $table SET value='$value', comments='$comments', editedBy='$editedBy', editedDate='$editedDate' WHERE projectId='$projectId';
I set the variables first of course, that’s not my question. Just pretend they have data. My question is how can i repeat this query so that every row table x that has a projectId of n is updated? I’m guessing this involves a for loop?
SIDE NOTE: Since this query is just setting the value to false and making the comments, editedBy, and editedDate fields blank for every row in table x that has a projectId of n, is there a better way of doing this other than the UPDATE query?
Thanks for any help!
As long as you don’t sepcify a
LIMITin yourUPDATEquery, it will update every row it finds that satisfies your where clause.Now, if you’re updating the projects table and
projectIDis your primary key, you’ll need to run a loop to update otherprojectIDs. If you’re not updating the project table, then your update query will update any record that has a foreign key match to the project ID you specified.Does that help?