Page 1 of 1

Help with a scheduling form

Posted: Sun May 02, 2010 11:53 am
by ChrisF79
Greetings:

I'm working on a form where a client can schedule their employees for work. The idea is that there will be a table with the employee names going down one column, and then for each day going off to the right, there's two checkboxes for day shift and night shift. The manager can then check the box for when each employee will work and hit submit. The problem is, I'm not sure how to handle this form.

Can anybody give me an idea as to how I could name the checkboxes so that I can process the results on the following page and submit it to the database? Any tips, suggestions, help would be greatly appreciated!

Re: Help with a scheduling form

Posted: Mon May 03, 2010 1:54 am
by rahulzatakia
Hi, tryout the below code..

Code: Select all


<?php
$link = mysql_connect("localhost", "username", "password");
mysql_select_db("Database name", $link);

$sql = "select emp_name from employee";
$res = mysql_query($sql);
$checkbox = "checkbox";
$i = 0;
?>
<form id="form1" name="form1" action="" method="post"><table>
<tr><td>Employee name</td><td>Day Shift</td><td>Night Shift</td></tr>
<?php
while($row = mysql_fetch_array($res))
{
	$checkname = $checkbox.$i;
	print "<tr><td>".$row[0]."</td><td><input type='checkbox' name='$checkname' value='Day_Shift'></td><td><input type='checkbox' name='$checkname' value='Night_Shift'></td></tr>";
	$i++;
}
?>
  </table>
</form>

It will fetch the employee name from database and will display the employee name with checkbox for day and night shift. And the checkbox will have different name like checkbox0 for 1st employee, checkbox1 for 2nd employee and so on... And if you have any query about this code or have other question then fill free to ask.. and give the reply if it is working fine with you or not....