Help with a scheduling form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ChrisF79
Forum Commoner
Posts: 26
Joined: Tue Apr 01, 2008 8:26 pm

Help with a scheduling form

Post 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!
rahulzatakia
Forum Commoner
Posts: 59
Joined: Fri Feb 05, 2010 12:01 am
Location: Ahmedabad

Re: Help with a scheduling form

Post 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....
Post Reply