Page 1 of 1

update all as a array

Posted: Thu Apr 17, 2003 2:50 am
by valen53
my problem is i dunno how to update data for each person. code will like that.....

select * from employee
display the employee list, can be many person ... it contain some of the field can be edit for each person.
after user edit the data for each person then click a update button to update for all of employee. but the problem is that system how to know which record was belong to certain employee? and how to updated it ?

anyone can help me ? thank a lot

Posted: Thu Apr 17, 2003 3:45 am
by twigletmac
Do you have a unique ID for each employee?

Mac

Posted: Thu Apr 17, 2003 4:00 am
by valen53
yes,the code was something like that...
while(... ) {
<td>'.$row[EMP_ID].'</td>
<td><input name="hours" type="text" value="'.$row[HOURS].'" >
<td><select name="status">
<option value="0" selected>approved</option>
<option value="2">reject</option>
</select></td>
}

so how to know hours textfield are belong to that user ? when update field, how to do it ?
thank ur reply

Posted: Thu Apr 17, 2003 4:55 am
by Tubbietoeter
valen53 wrote:yes,the code was something like that...
while(... ) {
<td>'.$row[EMP_ID].'</td>
<td><input name="hours" type="text" value="'.$row[HOURS].'" >
<td><select name="status">
<option value="0" selected>approved</option>
<option value="2">reject</option>
</select></td>
}

so how to know hours textfield are belong to that user ? when update field, how to do it ?
thank ur reply

try something like

while(... ) {
<td>'.$row[EMP_ID].'</td>
<td><input name="hours" type="text" value="'.$row[HOURS].'" > </td>
<input type="hidden" name="EmpNo" value="$row[EMP_ID]">
<td><select name="status">
<option value="0" selected>approved</option>
<option value="2">reject</option>
</select></td>
}


and remember to close all html tags

Posted: Thu Apr 17, 2003 7:56 am
by volka
if you want to change multiple entries with one request you might also name the elements using arrays/keys.
e.g.

Code: Select all

<?php
$dummyEmpIds = array(1,2,7,45,73);
?><?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html> 
	<head>
		<title>test page</title>
	</head>
	<body>
		<pre>
			<?php print_r($_POST); ?>
		</pre>
		<form method="POST" action="http://localhost/test.php">
			<p>
<?php
foreach($dummyEmpIds as $EMP_ID)
{
?>
				<input type="text" name="hours[<?php echo $EMP_ID; ?>]" /> : #<?php echo $EMP_ID; ?>
				<br />
<?php
}
?>	
				<input type="submit" />
			</p>
		</form>
	</body>
</html>

Posted: Thu Apr 17, 2003 10:56 pm
by valen53
<td>'.$row[EMP_ID].'</td>
<input type="text" name="hours[<?php echo $EMP_ID; ?>]" /> : #<?php echo $hours; ?>
<select name="status">
<option value="0" selected>approved</option>
<option value="2">reject</option>
</select>

-------post--------------
<?php print_r($_POST); ?> -- display the record

how we get the each of the value ? i only can get the $hours, but how to get $status and $emp_id ?
foreach ($_POST['hours'] as $hour) {
printf($hour) ;
}

Posted: Fri Apr 18, 2003 3:56 am
by volka

Code: Select all

foreach ($_POST['hours'] as $id=>$hour)
	echo $id, ': ', $hour;