I am trying to update my one table where there are several records but I want to update those all in a sequence from an array like as array is associative array so I want to update first record with first array items then 2nd record with 2nd array items but Instead what I have tried through following code is that my last array is updated into each record.I don't have any WHERE
clause in my query..!
Here is my code :
$json = '[
{
"x": 0,
"y": 0
},
{
"x": 4,
"y": 0
}
]';
$decoded_json = json_decode($json,true);
foreach ($decoded_json as $row) {
$x=$row['x'];
$y=$row['y'];
$query = mysqli_query($mysqli,"UPDATE clients SET x='$x',y='$y'");
}
Here is my clients
Table SHOW CREATE :
CREATE TABLE `clients` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`full_name` text NOT NULL,
`age` text NOT NULL,
`city` text NOT NULL,
`profession` text NOT NULL,
`client_id` text NOT NULL,
`info` text NOT NULL,
`profile_photo` text NOT NULL,
`x` text NOT NULL,
`y` text NOT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1