我有一个来自数据库的查询,看起来像这样
[{"id":"1","value":"1"},{"id":"3","value":"1"},{"id":"18","value":["1"]},{"id":"17","value":"1"},{"id":"5","value":"1"},{"id":"19","value":"-"},{"id":"20","value":"-"},{"id":"11","value":"-"},{"id":"12","value":"-"},{"id":"13","value":""},{"id":"9","value":"-"},{"id":"15","value":"-"},{"id":"16","value":"1"}]
我只想更新id 16旁边的值。
我现在改变整个字段而不仅仅是id为16的值。 我有这个
$query = "update kxmkw_k2_items set extra_fields='".mysql_escape_string($_POST["beschikbaarheid"])."' where id='".mysql_escape_string($_POST["id"])."'";
我怎样才能更新id 16旁边的值? 非常感谢(Y)
更新: 我发送查询的方式:
<?php
$item_id = JRequest::getVar('Itemid');
$db = & JFactory::getDBO();
$query = "SELECT extra_fields FROM #__k2_items WHERE id =".$item->id;
$db->setQuery($query);
$row = $db->loadResult();
$row = json_decode($row, TRUE);
$testitem = $row[12][value];
$testitem2 = ($testitem-1);
$db2 = & JFactory::getDBO();
$query2 = "SELECT value FROM #__k2_extra_fields WHERE id =16";
$db2->setQuery($query2);
$row2 = $db->loadResult();
$row2 = json_decode($row2, TRUE);
echo $row2[$testitem2][name];
?>
<form id="beschikbaarheidform<?php echo $item->id ?>">
<select name="beschikbaarheid" onChange="updateDb<?php echo $item->id ?>()">
<option value="1">Alleen uitleen</option>
<option value="2">Alleen verkoop</option>
<option value="3">Uitleen en verkoop</option>
<option value="4">Tijdelijk niet beschikbaar</option>
<option value="5">Verkocht</option>
</select>
<input type='hidden' name='id' value="<?php echo $item->id?>"/>
</form>
<script>
function updateDb<?php echo $item->id ?>() {
$.post("updateDB2.php", $("#beschikbaarheidform<?php echo $item->id ?>").serialize());
}
</script>