phpanon Posted March 4, 2008 Share Posted March 4, 2008 Hi people, This is my first time on this site so not sure how it all works exactly. Im fairly new to php and am building a test portal system for a small company. It needs to be able to allocate the users tasks for each day of the week. I have done this by looping through the tasks that are stored in the database, then for each one creating a drop down menu that lists all the employees. The User would then go through each task individually and allocate them to an employee. Then click submit and I want it to store the multiple tasks and who they are assigned to into the database. I believe I need to use an array of some sort to store all the values in, but haven't had mch experience with them so would be very greatful if someone could show me or help me in anyway. Thanking you in advance. <table width="860" > <hr /> <tr> <th width="142"><div align="left" class="style2">Task Name</div></th> <th width="262"><div align="left" class="style2">Description</div></th> <th width="140"><div align="left" class="style2">Weekday</div></th> <th width="140"><div align="left" class="style2">Assign</div></th> </tr> <?php //Build Select Menu $employee_list = '<select name="empID"><option>Select an Employee</option>'; while ($row2 = mysql_fetch_array($result2)) $employee_list .= '<option value='.$row2['empID'].'>'.$row2['fName'].' '.$row2['sName'].'</option>'; $employee_list .= '</select>'; while($row = mysql_fetch_array($result)) { ?> <tr> <td height="27"><?php echo $row['taskName']; ?></td> <td><?php echo $row['taskDescription']; ?></td> <td><?php echo $row['weekday']; ?></td> <td><form action="taskAdminQuery.php" method="post"><?php echo $employee_list; ?></td> </tr> <?php } ?></td> </tr> </table> <input name="Save" type="submit" value="Allocate Tasks" /> </form> <form action="TaskClear.php"> <input name="Clear" type="submit" value="Clear Tasks" /> </form> </div> <?php require "connect.php"; //$empName = $_GET['empName']; //$empID = $_GET['empID']; //$taskID = $_GET['taskID']; $task = array(); $task['empID'] = $_POST['empID']; $task['taskID'] = $_POST['taskID']; foreach($task as $key => $anothertask) { $query = "insert into emptask (taskID, empID, emptaskweekDay, complete) values ('".$taskID."','".$empID."','Monday','N')"; $result = @mysql_query($query, $connection) or die ("Error:".mysql_error()); } $message1 = "Tasks Allocated Successfully."; header("Location: TaskAdmin.php?message1=$message1"); exit(); //} ?> Quote Link to comment Share on other sites More sharing options...
craygo Posted March 4, 2008 Share Posted March 4, 2008 What I would do is have the select name be the task and the employeeid be the value. i have not tested this but <table width="860" > <hr /> <tr> <th width="142"><div align="left" class="style2">Task Name</div></th> <th width="262"><div align="left" class="style2">Description</div></th> <th width="140"><div align="left" class="style2">Weekday</div></th> <th width="140"><div align="left" class="style2">Assign</div></th> </tr> <?php while($row = mysql_fetch_array($result)){ ?> <tr> <td height="27"><?php echo $row['taskName']; ?></td> <td><?php echo $row['taskDescription']; ?></td> <td><?php echo $row['weekday']; ?></td> <td> <form action="taskAdminQuery.php" method="post"> <select name="<?php echo $row['taskName']; ?>"> <option selected>--Select an Employee--</option> <?php while ($row2 = mysql_fetch_array($result2)){ echo "<option value=\"".$row2['empID'].">".$row2['fName']." ".$row2['sName']."</option>\n"; } ?> </select> </td> </tr> <?php } ?> </table> <input name="Save" type="submit" value="Allocate Tasks" /> </form> <form action="TaskClear.php"> <input name="Clear" type="submit" value="Clear Tasks" /> </form> </div> now you can use a foreach on the post values <?php foreach($_POST as $taskID => $empID){ { // don't want to run query on the submit button if($taskID != "Save"){ $query = "insert into emptask (taskID, empID, emptaskweekDay, complete) values ('".$taskID."','".$empID."','Monday','N')"; $result = @mysql_query($query, $connection) or die ("Error:".mysql_error()); } } ?> Ray Quote Link to comment Share on other sites More sharing options...
phpanon Posted March 4, 2008 Author Share Posted March 4, 2008 Hello, I implemented your suggestions. It doesn't seem to be working, plus now only the first drop down menu lists the employee names, leaving the others blank?! The table is also slightly distorted now with the second task in the table ending up in the drop down menu along with the employees. just to re-iterate what I need it to do :- There is a table listing all the tasks that need to be completed on a monday. Then in the last column of the table is a drop down menu that lists all the employees, there is a drop down menu for each task that loops out of the database into the table. I want the user to be able to look at each task and then allocated each task to an employee. Once all are assigned save those to the database so that when the user signs in they can look at what tasks they have been allocated. Quote Link to comment Share on other sites More sharing options...
craygo Posted March 4, 2008 Share Posted March 4, 2008 I made a mistake with the order of the code <table width="860" > <hr /> <tr> <th width="142"><div align="left" class="style2">Task Name</div></th> <th width="262"><div align="left" class="style2">Description</div></th> <th width="140"><div align="left" class="style2">Weekday</div></th> <th width="140"><div align="left" class="style2">Assign</div></th> </tr> <?php $sql1 = "SELECT * FROM emptask"; $result = mysql_query($sql1) or die(mysql_error()); echo "<form action=\"taskAdminQuery.php\" method=\"post\">\n"; while($row = mysql_fetch_array($result)){ ?> <tr> <td height="27"><?php echo $row['taskName']; ?></td> <td><?php echo $row['taskDescription']; ?></td> <td><?php echo $row['weekday']; ?></td> <td> <select name="<?php echo $row['taskID']; ?>"> <option selected>--Select an Employee--</option> <?php $sql2 = "SELECT empID, fname, sName FROM employeetable"; $result2 = mysql_query($sql2) or die(mysql_error()); while ($row2 = mysql_fetch_array($result2)){ echo " <option value=\"".$row2['empID']."\">".$row2['fName']." ".$row2['sName']."</option>\n"; } ?> </select> </td> </tr> <?php } ?> </table> <input name="Save" type="submit" value="Allocate Tasks" /> </form> <form action="TaskClear.php"> <input name="Clear" type="submit" value="Clear Tasks" /> </form> </div> i put some queries in there to test, but you need to move the employee query to inside the loop. Ray Quote Link to comment Share on other sites More sharing options...
phpanon Posted March 4, 2008 Author Share Posted March 4, 2008 absolutely superb. Thank you very much for your help!! I have a feeling I may use this forum more often Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.