Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update Multiple Records , 1 Form 1

Status
Not open for further replies.

JSProgramIA

Programmer
Oct 28, 2005
41
US
I suppose a picture is worth a 1000 words:

ss.jpg


I know I have to user arrays somehow on each row, most likely by adding the project_id ( the primary key ) somewhere in the array.

Could someone post a simple example on how to approach my problem? I am getting lost in this for each stuff.

Thanks.
 
It's all a question of naming conventions for HTML form elements. All you need to do is to name the form elements as arrays:
Code:
<select name="client[COLOR=red][][/color]">
 
Thanks, I have gotten that far.

Let's assume on each row there are appropriate field names, such as client[] , project[], etc.

when i go to update ALL these records, how do I loop through each one?

Just psuedocode is needed, nothing specific.

For instance, I am sure it is something like this:

Code:
if($form_was_submitted){

     /* Loop through all fields */
     foreach( SOMETHING AS SOMETHING-ELSE HERE ) {

         /* Get the Primary Key from Hidden Field
            so I know what record to update */

         $id = $_POST['id'];  <----- WON'T WORK, IT's AN ARRAY OF MANY ID's

         /* Now Update the record */

         $updated_Project = ....
         $updated_Client  = ....

         etc...


     }

}

See where I am going with this?

Thanks for any advice.
 
The concept is actually fairly easy.
You use a foreach loop to iterate one of the arrays, e.g. the client. You only need keep track of the index in the array:
Code:
foreach ($_POST['client'] AS $offset=>$value){
   # now $offset can be used to point to the other values in the remaining arrays.
   /* Now Update the record */
   $updated_Project = $_POST['project'][$offset];
   $updated_Client  = $value;
}

The only mishap that you have to take vare of client side is to make sure that lines are filled out entirely. You don't want somebody select a client and not report the other values.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top