I'm not entirely certain how descriptive that title is, but:
In Wordpress I have a custom table of numerical data which gets added to monthly (via a spreadsheet import). As such, I'm using $wpdb
to pull the contents of that table, which gets returned as an array of stdClass objects:
Array
(
[0] => stdClass Object
(
[id] => 553
[assocID] => 1
[title] => Afghanistan
[weight_political] => 8.2
[indicator_political] => 0.0
[weight_security] => 9.5
[indicator_security] => 0.0
[weight_criminal] => 9.5
[indicator_criminal] => 1.0
[weight_governance] => 9.0
[indicator_governance] => 0.0
[overall_score] => 9.2
[datamonth] => 2013-08-18
[active] => 1
)
[1] => stdClass Object
(
[id] => 369
[assocID] => 1
[title] => Afghanistan
[weight_political] => 8.4
[indicator_political] => 0.0
[weight_security] => 9.5
[indicator_security] => 0.0
[weight_criminal] => 9.3
[indicator_criminal] => 1.0
[weight_governance] => 9.0
[indicator_governance] => 0.0
[overall_score] => 9.2
[datamonth] => 2013-07-05
[active] => 1
)
)
This is fine and gives me exactly what I want, which I can then echo out as a series of input fields to edit (see my jsFiddle for example output).
However, what I can't get my head around (and I'm pretty sure I'm just being super-stupid here and missing something obvious) is saving the appropriate data back to the appropriate database row.
I've considered setting the input names as arrays (i.e. <input name="weight_security[]"...
), but it's clearly missing a reference. I want the August 2013 data (id 553) to be saved to the August 2013 row; I just can't figure out where or how to implement that reference.
In this example there's only 2 rows, but there could be as many as 14 once this is live, and will be added to monthly, so the ability to modify multiple rows simultaneously is key.
Any help is greatly appreciated.