I'm trying to create a form that will query my database for a list of active employees and then allow me to put in the hours they worked on a line. Each line will have this form with all the active employees listed. We have several employees that move between lines all day long, but we also have some that don't change lines. Here is what I have created so far:
<head>
<title>Production Employee List</title>
</head>
<body>
<div align="center">
<table width="300" border="1" cellpadding="4" style='border-collapse: collapse'>
<tr>
<td colspan=4 align=center bgcolor="#CCCCCC"><strong>Select Production Line</strong></td>
</tr>
<tr>
<td colspan=4 align=center><select id="line" name="line">
<option selected>- Click Here -</option>
<?php
include 'config.php';
/*** create a new mysqli object with default database***/
$connection = mysqli_connect($hostname, $username, $password, $dbname) or die ("Unable to connect");
//create query
$query1 = "SELECT id, production_line FROM prod_line where active = 'yes'";
//excute query
$result1 = mysqli_query($connection, $query1) or die ("Error in query: $query1. ".mysqli_error());
//create list of variables from query results
while(list($pid, $prod_line) = mysqli_fetch_row($result1))
{
echo "<option value=$pid>$prod_line</option>";
}
?>
</option>
</select>
</td>
</tr>
<tr>
<td colspan="4"> </td>
</tr>
<p>
<div align="center">
<tr>
<td width="50" bgcolor="#CCCCCC"><div align="center"><strong>ID</strong></div></td>
<td width="125" bgcolor="#CCCCCC"><strong>First Name</strong></td>
<td width="125" bgcolor="#CCCCCC"><strong>Last Name</strong></td>
<td width="100" bgcolor="#CCCCCC"><strong>Hours</strong></td>
</tr>
</body>
<?php
//create query
$query = "SELECT id, fname, lname FROM prod_employee where active = 'yes'";
//excute query
$result = mysqli_query($connection, $query) or die ("Error in query: $query. ".mysqli_error());
// see if any rows were returned
if (mysqli_fetch_array($result) > 0) {
// yes
// print them one after another
while (list($id, $fname, $lname) = mysqli_fetch_row($result))
{
echo " <tr>
<td><div align=center>$id</div></td>
<td>$fname</td>
<td>$lname</td>
<td><input name=$id-hours type=text size=4 maxlength=4 />
</tr>";
}
echo "</table>";
}
else {
// no
// print status message
echo "No rows found!";
}
// free result set memory
mysqli_free_result($result);
// close connection
mysqli_close($connection);
?>
<tr>
<td colspan = 4><div align="center"> </div></td>
</tr>
<tr>
<td colspan = 4><div align="center"><input type="submit" name="Submit" value="Submit">
</div></td>
</tr>
<tr>
<td colspan = 4><div align="center"> </div></td>
</tr>
<tr>
<td colspan = 4><div align="center"><a href="index.php">Home</a></div></td>
</tr>
</table>
</div>
</body>
This all works well enough, but here is where I get into trouble. I now want to be able to insert the employees that have worked on that line and the number of hours into my database (would like to leave out the blanks from the form). This way I can see how many hours were used on each line per day. I'm thinking that I will need to create an for each array??? Does that sound correct? I'm not the best at arrays just yet, but wanting to learn how to do them correctly. If someone could tell me if I'm correct or tell me what they would do, I would great appreciate it. Thanks for any help you can provide.
A