Jump to content

[SOLVED] Updating data from multiple rows


tlflow

Recommended Posts

Picture this:  I'm returning rows of a list of people in my team.  But each row at the end has a dropdown which allows me to chagne that the role for that person.  In each option value line I am returning the persons ID and new role seperated by a <space> (for ex. <select name="newteamrole"><option value="5 PointGuard"></select>.

 

Once I submit, I seem to be getting the variables I want by using explode(), and if I do just simple echo commands the strings seem to come out right, but nothing is updating in my database.

 

Here's what I have so far:

 

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");


	foreach ($_POST['newteamrole'] as $entry) 
	{
   	$variable = explode(" ", $entry);

	$newrole = $variable[0];
	$person = $variable[1];

	// echo ("$person is a(n) $newrole <br>");

	$query = "update people SET team_role = '$newrole' where userid = '$person'"; 

	// echo ("update people SET team_role = '$newrole' where userid = '$person' <br>"); 

	}

mysql_query($query);


mysql_close();

 

Is there a problem with me doing it this way?  Anybody got any idea what I'm doing wrong????

 

Thanks,

 

TL

Link to comment
https://forums.phpfreaks.com/topic/46800-solved-updating-data-from-multiple-rows/
Share on other sites

I really appreciate your help on this one!  This one has me stumped!

 

I tried the change, yet I'm still getting the same results (nothing is being updated to the database).

 

But to answer your question, I thought I would have to "foreach" variables since I'm returning more than one person at one time.  I'm trying to set the role for everyone on a team at the same time in one submit...

 

for example my form would look like this,

 

row1 = Fred --> 5--> <select name="newteamrole"><option value="5 PointGuard"><option value="5 ShootingGuard"><option value="5 Forward"><option value="5 PowerForward"><option value="5 Center"></select>

 

row2 = Jim --> 15 --> <select name="newteamrole"><option value="5 PointGuard"><option value="5 ShootingGuard"><option value="5 Forward"><option value="5 PowerForward"><option value="5 Center"></select>

 

row3 = Jake --> 34 --> <select name="newteamrole"><option value="5 PointGuard"><option value="5 ShootingGuard"><option value="5 Forward"><option value="5 PowerForward"><option value="5 Center"></select>

 

and so on...

 

Role is selected in the newteamrole dropdown and I just have the ID with it (seperated by a space for the explode).

 

Foreach was the only way I could think of to get multiple variables to the next page.

 

 

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.