dynamic form

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.
LVL 7
UniqueDataAsked:
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.

Ray PaseurCommented:
No points for this, please, because it's not an answer.  But it may provide some useful "getting started" information.  If you're new to PHP and server-side web application development, this article may help you get started.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11769-And-by-the-way-I-am-new-to-PHP.html

The general design pattern for what you're doing may be found in the concept of "SQL table maintenance."
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_12335-PHP-and-MySQLi-Table-Maintenance.html
0
UniqueDataAuthor Commented:
Thanks Ray, you have helped me plenty of times and these links are not new to me and I refer back to them from time to time.

However I didn't see anything in these articles that helped with this task at hand as part of my question is asking for suggestions on the best way to set up the html table/form given the way the user wants the data displayed and how it is to be stored.  What would be the easiest way to build the tables to allow for easy looping to write back to my database table.
0
UniqueDataAuthor Commented:
Ok.  Let me post what I came up with to build the table.

		          <tbody>
          		<?php 
          			foreach ($staffArray as $key => $value) {
          				echo "<tr>";
          				echo "<td class='headcol'>".$value."<input type='hidden' name='uuk[]' value='".$key."'></td>";
						$rstActivities = mysql_query($sql);          					
  						while($row = mysql_fetch_assoc($rstActivities))
      					{
							echo "<td><input class='qty' activityID='".$row['ActivityID']."' type='text' name='Units[]' size='4'></td>";
							echo "<td><input class='regHrs' activityID='".$row['ActivityID']."' type='text' name='RegHours[]' size='4'></td>";
							echo "<td><input class = 'otHrs' type='text' activityID='".$row['ActivityID']."' name='OTHours[]' size='4'></td>";						
						}      					

					echo "</tr>";
					}
				?>
	            </tbody>

Open in new window


So each row of the table will have one staffID and multiple activity records. The activities table structure is:  StaffActivity.StaffID (this will be the uuk[] value), StaffActivity.ActivityDate, StaffActivity.ActivityID, StaffActivity.Units, StaffActivity, RegHours, and StaffActivity.OTHours

I figured I could add an element in each <td> called ActivityID to help, but not sure how any of this will work.

So again, the question is, what does php code look like to append the many records?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

UniqueDataAuthor Commented:
I found a post that may be leading me the correct way, change the names of my fields:

          		<?php 
          			foreach ($staffArray as $key => $value) {
          				echo "<tr>";
          				echo "<td class='headcol'>".$value."</td>";
						mysql_data_seek($rstActivities, 0) ;      					
  						while($row = mysql_fetch_assoc($rstActivities))
      					{
							echo "<td>";
								echo "<input type='hidden' name='entry[uuk]' value='".$key."'>";
								echo "<input type='hidden' name='entry[ActivityID]' value='".$row['ActivityID']."'>";
								echo "<input class='qty' type='text' name='entry[Units]' size='4'>";
							echo "</td>";
							echo "<td><input class='regHrs' type='text' name='entry[RegHours]' size='4'></td>";
							echo "<td><input class = 'otHrs' type='text' name='entry[OTHours]' size='4'></td>";						
						}      					

					echo "</tr>";
					}
				?>

Open in new window

0
David Johnson, CD, MVPOwnerCommented:
a picture is worth a thousand words..you have to structure your mysql query until you get the dataset returned the  way you want it... then in server side code you run the query and populate the dataset  then you can then format the table
0
UniqueDataAuthor Commented:
I was able to get an answer to the partial code in my last post.

I opened another question and got a solution:
  http://www.experts-exchange.com/Programming/Languages/Scripting/PHP/Q_28632534.html
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
UniqueDataAuthor Commented:
I was able to get my question answered by google and posting another question
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.