my code is :
//This is the data I am getting [{"x":1,"y":0,"width":2,"height":10},{"x":6,"y":0,"width":2,"height":9}]
<?php
$position = json_decode($_POST['positionData'], true);
$select_id = "SELECT id FROM homegrid";
$select_id_exec = mysql_query($select_id);
//print_r($position[1]);
//print_r($position[2]);
//getting result seperately
foreach ($position as $entry) {
$x = $entry['x'];
$y = $entry['y'];
$width = $entry['width'];
$height = $entry['height'];
$positionjson = json_encode($entry);
//print_r($positionjson);
while($idFromDB = mysql_fetch_assoc($select_id_exec)) {
//print_r($idFromDB);
//echo $update = "update homegrid set position = '$positionjson' WHERE id = '" . $idFromDB['id'] . "' ";
//mysql_query($update);
}
}
?>
The output of update query is
update homegrid set position = '{"x":6,"y":0,"width":2,"height":9}' WHERE id = '7'
update homegrid set position = '{"x":6,"y":0,"width":2,"height":9}' WHERE id = '8'
that means result of last position of array is getting.
How can i get result like
update homegrid set position = '{"x":1,"y":0,"width":2,"height":10}' WHERE id = '7'
update homegrid set position = '{"x":6,"y":0,"width":2,"height":9}' WHERE id = '8'
?
My table structure is given below
id position
7 {"x":1,"y":0,"width":2,"height":10}
8 {"x":6,"y":0,"width":2,"height":9}
Could you please help me to solve this issue?