I have a data as json format in mysql database table as mentioned below.
{
"dataType": "mis_type",
"diceCode": "20070100102",
"forms": {
"4. Campus": {},
"7. Classroom": {},
"1. Details of school": {
"School_Name": "GOVT. UPG .M.S. KHAGARA",
"Village_Name": "KHAGARA",
"Block_Name": "MOHAN PUR",
"Dist_Name": "DEOGHAR",
"Type_of_School": "DEPARTMENT OF EDUCATION",
"Category": "PRIMARY WITH UPPER PRIMARY",
"No_of_Student": 209,
"No_of_Section": 8,
"No_of_Classroom": 5,
"Govt_Teacher": 2,
"Para_Teacher": 3,
"Other_Teacher": 0,
"Total_Teacher": 5,
"Total_Toilet": 2,
"Total_Urinals": 2
},
"6. Drinking Water Source": {},
"8. Kitchen Shed": {},
"2. Location of School": {},
"5. Location of Toilet": {},
"3. Pollution Status": {
}
}
}
I am trying to replace “ Total_Toilet ” value from another new value . For that I wrote following code.
$selectQuery = "SELECT `json_data` FROM `abc` WHERE `disc_code`='" . $diseCode . "' AND `type`='mis'";
$res = $conn->query($selectQuery);
$jsonvalue = $res->fetch_assoc();
$jsonvalue = json_decode($jsonvalue['json_data'], true);
unset($value['Dise_Code']);
unset($value['OBJECTID']);
if ($res->num_rows > 0)
{
foreach( $jsonvalue['forms']['1. Details of school'] as $key1 => $value1 )
{
echo"<br>";
$key2 = str_replace($jsonvalue['forms']['1. Details of school'] ['Total_Toilet'] , 4, $value1 ) ;
echo $key2;
}
The code is being compiled without any error but still the previous value is not getting replaced by the new value using str_replace function. If there is something wrong I am doing then please guide me or if any alternative solution anyone know please help me.
Any help would be appreciated.