I have the following JSON.
{
"studentIDPMKEY": "23",
"Grades": [{
"studentid": "23",
"Maths": "C",
"History": "B"
}]
}
Now, I need to update this data into the SQL table.
But First, I need to do an SQL query to check if the student exists, then enter the grades. So I have written a function which checks if a student exists.
This is the Update statement
foreach($obj->student as $st){
$studentid= $st->studentid;
$maths= $st->Maths;
$history= $st->History;
$insert = $mysqli>prepare("UPDATE grades SET $maths=?, $history=? WHERE studentid= ?");
$insert->bind_param("iss",$studentid,$maths, $history);
$insert->execute();
}
Now
What I want to do is, get the studentIDPMKEY and check if the student exist.
if (isset($_POST['studentIDPMKEY ']) && $_POST['v'] != "") {
}
My question is how can I loop through the above JSON string, first get the studentIDPMKEY , do the check than carrying on with update statement.