iwiniquit Posted December 9, 2007 Share Posted December 9, 2007 I'm trying to update my database using an array and a foreach loop. It's basically just updating/resorting a list of numbers. The problem I'm having is that I'm trying to updating several lists using one javascript function and sending it to the same php file that has one foreach loop. Here's the php I'm using $project_id = $_POST['project_id']; $i=1; foreach($_POST['client_list_1'] as $key=>$value) { mysql_query("UPDATE `projectClients` SET position='".$i."' WHERE project_id = $project_id AND client_id ='".$value."'\n"); $i++; } This works fine. The problem I'm having is that instead of client_list_1. I want to make it so I can change the 1 into the number that $project_id has. My logic would be to replace $_POST['client_list_1'] with $_POST['client_list_$project_id'] but that of course doesn't work. If that did work, it would be perfect. So that's what I'm trying to accomplish. I'm not sure if this helps but the code that sends everything over to the php file is: echo(" <script type=\"text/javascript\"> function updateOrder() { var project_id = $project_id; var options = { method : 'post', parameters : Sortable.serialize('client_list_'+project_id)+'&project_id='+project_id, // Handle successful response onSuccess: function(t) { alert(t.responseText); }, // Handle 404 on404: function(t) { //alert('Error 404: location \"' + t.statusText + '\" was not found.'); }, // Handle other errors onFailure: function(t) { //alert('Error ' + t.status + ' -- ' + t.statusText); } }; new Ajax.Request('Includes/lib/clients/drag_update_client.php', options); } Sortable.create(\"client_list_$project_id\", {constraint:\"vertical\", onUpdate : updateOrder}); </script> "); Quote Link to comment Share on other sites More sharing options...
iwiniquit Posted December 9, 2007 Author Share Posted December 9, 2007 Nevermind, I figured it out. I just had to do: $_POST['client_list_' . $project_id . '']; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.