This topic is locked

Submitting multiple entries at one time

12/21/2008 4:05:31 PM
PHPRunner General questions
vin7102 author

Hello all,
I'm looking for some Ideas on adding multiple entries to a database within one add record page and any ideas would be greatly appreciated.
My project is an employee time sheet/ Payroll log. Basically, each foreman has about 15 employees on a crew and each crew can work on

multiple jobs in a day. I currently have an "Add record" page that has all the information I need in the database (Employee_Name, Job_Name, Job_Description, Foreman_Name, Date, and Hours_Worked)

How can I be able to enter all the job information and then select the 15 employees from a list or check boxes and have phprunner create a new database entry for each of the selected employees in one shot.

I've noticed that when you select a drop down box with multiple rows option at say 10, you can hold Ctrl while selecting to select multiple names but when submitted to the database, there is only one line

entry and all the names that were selected are added (comma separated) into the "Employee_Name" field of the database.

In order to be able to set up payroll reports and searches effectively, I would need a separate line entry for each employee name.

As it stands, I'm using session variables to hold the values on the "add record" page so the foreman won't have to re-enter All of the job information over and over again, but

the foreman will still have to choose each employee one at a time to be logged into the database and hope that he doesn't omit or duplicate any entries on accident.
Any help ore advice would be great

Thanks

Vince

A
alang 12/22/2008

I have done a similar sort of thing using following process:

  1. Add code to the "Before record added" event

  • generate an array of records you want to add
  • loop through the array ("foreach") and call SQL to insert into the database

  1. Don't return a value from the event function - I jump back to the list page

  • header("Location: ... ");
  • exit();
    This approach is OK if you know the list of records you want to add (no user input).
    Another approach is to hijack one of the multiple functions on a list page (edit, print, export, delete) and apply you own process. This allows the user to select an arbitrary set.
    In your case if you already know who is in your crew, you are probably better off with the first approach.
    There are other postings about the multiple items in the dropdown only creating one record - basically I think you get a single string with all the selected values in it and you have to manually break it up (explode function) to create an array - then use first approach as above.

T
thesofa 12/22/2008

I have had to do this for a similar thing, look here, if you need more info, drop me a note and I will explain more.

Please note this solution works for version 4.2, not sure if it is OK with 5