Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi, I have a dynamically generat 1

Status
Not open for further replies.

Nematoth

Programmer
Mar 29, 2002
48
MY
Hi,

I have a dynamically generated page which list all users on a system. Next to each user is a checkbox. I want to be able to select multiple users (by checking the checkboxes)and then update another table in the database with the username associated with that checkbox.

The idea is that the user selects users to work on a project from the whole list of users. This would then update the table that relates the projects table to the users table by inserting a unique value, their username, and the project number.

I cannot seem to associate the checkboxes with the relevant username....

Does anyone have any ideas on how I can do this?
Thomas Shearer
Multimedia Developer
 
Name all the checkboxes something like "foo[]" (something like an array operator with an empty subscript). Set the value of each checkbox to the value necessary to find a coworker's database record, like the recordid from each coworker.

When the form is submitted, $_POST['foo'] will itself be an array, each element containing the record id of the checked coworkers.

For example, assume test_arrayinput.html reads as :
Code:
<html><body><form method=POST action=test_arrayinput.php>
	<input type=checkbox name=&quot;foo[]&quot; value=104>Amy
	<input type=checkbox name=&quot;foo[]&quot; value=219>Bill
	<input type=checkbox name=&quot;foo[]&quot; value=367>Charlene
	<input type=checkbox name=&quot;foo[]&quot; value=452>Don
	<input type=checkbox name=&quot;foo[]&quot; value=527>Ernesto
	<input type=submit>
</form></body></html>

And test_arrayinput.php reads as:
<?php
print '<pre>';
print_r ($_POST);
?>

Then if I open test_arrayinput.html in my browser; select Amy, Charlene, and Don; and submit, test_arrayinput.php outputs:
Array
(
[foo] => Array
(
[0] => 104
[1] => 367
[2] => 452
)
)

With this, you can loop through the IDs and perform your necessary database updates with only a foreach loop. Want the best answers? Ask the best questions: TANSTAAFL!
 
Cheers for that Sleipnir! Again you come to the rescue. Generally I do Multimedia Stuff (flash, director) and this is the first big thing I've done in PHP, so I'm still learning! But thanks for all your help. Thomas Shearer
Multimedia Developer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top