I am trying to loop through some data I post through jQuery. Here is my PHP script:
<?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 ++;
}
?>
and the data it is recieving as $map is sent in this format:
ID[]=27&ID[]=28&ID[]=33&ID[]=19
Obviously my foreach is wrong, but how would I go about getting it so that I retain $maps order and each numerical value becomes the variable $ID?
Ok, Since your $map contains,
ID[]=27&ID[]=28&ID[]=33&ID[]=19string value. Do something like thisP.S. Based on the OP’s comment of $map having a string output of that