We help IT Professionals succeed at work.
Get Started

dynamic form

259 Views
Last Modified: 2015-03-15
I need to create a form that gets its columns from a database (php/mysql).  
It will be in the following format:
		<form method="post" name="newActivities" action="addActivities.php">
	        
	        <div class="form-group">
	                <div class="row">
	                    <div class="col-md-4">
	                      <label for="activityDate">Date of Work</label>
	                      <input type="text" class="form-control" name="activityDate">
	                    </div>
	                </div>
            </div>
		    <table id="table" class = "udsGrid">
		          <thead>
	          			<tr>
	          				<th></th>
	          				<th colspan="3">600 POS Handling</th>
	          				<th colspan="3">601 Marketing Handling</th>
	          				<th colspan="3">602 E-Commerce Handling</th>
	          			</tr>
	              		<tr>
							<th>Staff</th>

							<th>Units</th>
							<th>Reg Hrs</th>
							<th>OT Hrs</th>

							<th>Units</th>
							<th>Reg Hrs</th>
							<th>OT Hrs</th>

							<th>Units</th>
							<th>Reg Hrs</th>
							<th>OT Hrs</th>														
	              		</tr>
		          </thead>
		          <tr>
						<td>Jones, Tom</td>
						<td><input type="text" name="Units1_Activity600"></td>
						<td><input type="text" name="RegHrs1_Activity600"></td>
						<td><input type="text" name="OTHrs1_Activity600"></td>
						<td><input type="text" name="Units1_Activity601"></td>
						<td><input type="text" name="RegHrs1_Activity601"></td>
						<td><input type="text" name="OTHrs1_Activity601"></td>
						<td><input type="text" name="Units1_Activity602"></td>
						<td><input type="text" name="RegHrs1_Activity602"></td>
						<td><input type="text" name="OTHrs1_Activity602"></td>
		          </tr>
		          <tr>
						<td>Doe, John</td>
						<td><input type="text" name="Units2_Activity600"></td>
						<td><input type="text" name="RegHrs2_Activity600"></td>
						<td><input type="text" name="OTHrs2_Activity600"></td>
						<td><input type="text" name="Units2_Activity601"></td>
						<td><input type="text" name="RegHrs2_Activity601"></td>
						<td><input type="text" name="OTHrs2_Activity601"></td>
						<td><input type="text" name="Units2_Activity602"></td>
						<td><input type="text" name="RegHrs2_Activity602"></td>
						<td><input type="text" name="OTHrs2_Activity602"></td>
		          </tr>		                                  
		    </table>
	    </form>

Open in new window


I'm guessing that as I loop through the recordset to get all the columns (600 POS, 601 Marketing, etc) and looping through a staff table to get a row for each staff member. I can use jquery to add the needed <th> and <tr> elements.  But here is where my difficulty is.  Each activity gets added as a seperate record:
StaffActivity.StaffID, StaffActivity.ActivityDate, StaffActivity.ActivityID (this is the 600, 601, etc), StaffActivity.Units, StaffActivity, RegHours, and StaffActivity.OTHours.

What is the best way to save each record to individual records.  I was thinking the names of the input controls could be used to store the ActivityID and StaffID????  Should the input controls be arrays? Should I add some type of identifier in the staff <td> cell?

Hope this all makes sense.
Comment
Watch Question
This problem has been solved!
Unlock 1 Answer and 7 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE