Updating Multiple Records

My problem is a little more complex but my basic problem will be the same. Using PHP and MySQL

If on a page I have a form, and I click the submit button, how do I update multiple records in a MySQL database?

Basically I have a page that pulls "time" from a table. I may have 5 "time" records for a single "client" So on this page, all "time" is shown in a repeat region for the specific "client". I click the form Submit button and a "invoice" table is filled with various information. What I need to do is take the "invoice number" from the invoice just created and Update all 5 records to show the correct invoice number in their proper fields. ..

...Make sense? On submit, I need to update multiple records with a variable.

Can anyone help me get started? I can update a record fine, it is the multiple record update that is puzzling me.
LVL 16
rbudjAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

eriksmtkaCommented:
You want the UPDATE clause for PHP.  Here is the website: MySQL :: UPDATE

UPDATE [LOW_PRIORITY] [IGNORE] table_reference
    SET col_name1={expr1|DEFAULT} [, col_name2={expr2|DEFAULT}] ...
    [WHERE where_condition]
    [ORDER BY ...]
    [LIMIT row_count]

Open in new window


Basically, it's UPDATE table_name SET col1='value1', col2 ='value2' WHERE col_identifier='value_to_find'

UPDATE doesn't just update 1 record, it updates all the records where the WHERE statement matches... it could be 1, it could be 5, it could be 1000.  Be careful though.  Make sure you have your WHERE clause written correctly.  You can update the whole table if you omit it!

You might also be interested in the "mysql_affected_rows()" function in PHP:  PHP - mysql_affected_rows

This function will tell you how many rows were actually update in the last UPDATE query (as well as INSERT, REPLACE and DELETE)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rbudjAuthor Commented:
Thank you very much eriksmtka. I thought I was going to have to go through loops to get this done. The WHERE statement is exactly what I needed. Thank you again.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.