To answer my own question: the key was in multidimensional arrays for the input names; so, instead of multiple fields like:
<input name="weight_political" value="8.2" />
<input name="indicator_political" value="0" />
I decided to go up a level and wrap these field names in an array called geodata
and, crucially, preface that with an array key that was the ID of the row that needed updating, thus:
<input name="geodata[553][weight_political]" value="8.2" />
<input name="geodata[553][indicator_political]" value="0" />
Then, when parsing the posted data, I can loop through the geodata
array to get the row ID (as the key), then the data as an associative array within that:
<?php
if ($_POST["geodata"]) {
foreach ($_POST["geodata"] as $rowID=>$valuesArray) {
$queryArray = array();
foreach ($valuesArray as $key=>$value) {
$queryArray[] = $key . ' = ' . $value;
}
$queryString = implode(', ', $queryArray);
$wpdb->query("UPDATE $table_name SET $queryString WHERE id = $rowID");
}
}
?>
Also:
To try to be as efficient as possible (since an initial 9x14 grid would return 126 values to update, many of them needlessly), I wrote a small jQuery function to detect when an input field was changed; if so, then its name
was changed from data[id][identifier]
to geodata[id][identifier]
- that way, $_POST['geodata']
would only send the values that needed to be updated, rather than the whole batch lot. jsFiddle below, for those who are interested.