Jump to content

Problem with array


almystersv

Recommended Posts

Hi Guys,

 

Im not entirely sure what im doing :-\

I have a basic internal system that needs an administrator to allocate tasks to members of staff.

 

I successfully have the loop working that displays all the tasks to the screen and allows a drop down menu with all the employees in it so each task can have an employee selected for it but now i just need to write it all to the database.

 

I understand that I'll need some form of array and a loop to run through it writing each one to the table but I dont really know hoe exactly to do it.

 

Your advice would truly help.

 

Thanks

 

Here is my 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
	//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();
//}
?>

Link to comment
https://forums.phpfreaks.com/topic/94007-problem-with-array/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.