Looping through post data and updating corresponding database records
<p>I am trying to loop through some data I post through jQuery.  Here is my PHP script:</p>

<pre><code>&lt;?php
include '../dbconnect.php';
$map = $_POST['map'];
$position = 0;
foreach ($map as $ID)
{
  if ($_POST['type'] == "sub") {
    $query = "UPDATE Subcategories SET `Position` = '$position' WHERE CategoryID = '$ID';";
  } else {
    $query = "UPDATE Categories SET `Position` = '$position' WHERE CategoryID = '$ID';";
  }

  $result = mysql_query($query) or die(mysql_error());
  $position ++;
}
?&gt;
</code></pre>

<p>and the data it is recieving as $map is sent in this format: </p>

<blockquote>
  <p>ID[]=27&amp;ID[]=28&amp;ID[]=33&amp;ID[]=19</p>
</blockquote>

<p>Obviously my <code>foreach</code> is wrong, but how would I go about getting it so that I retain <code>$map</code>s order and each numerical value becomes the variable <code>$ID</code>?</p>
