update all as a array

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
valen53
Forum Contributor
Posts: 137
Joined: Tue Aug 27, 2002 9:29 am

update all as a array

Post 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
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Do you have a unique ID for each employee?

Mac
valen53
Forum Contributor
Posts: 137
Joined: Tue Aug 27, 2002 9:29 am

Post 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
Tubbietoeter
Forum Contributor
Posts: 149
Joined: Fri Mar 14, 2003 2:41 am
Location: Germany

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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>
valen53
Forum Contributor
Posts: 137
Joined: Tue Aug 27, 2002 9:29 am

Post 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) ;
}
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Code: Select all

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