ESH/data_cleanup.php
2024-10-23 18:28:06 +05:30

32 lines
1.2 KiB
PHP

<?php
error_reporting(E_ERROR | E_PARSE);
include('includes/config/config.php');
include('includes/functions.php');
$query = "select * from employee_appointment where appointment_date >= '2023-10-04 00:00:00' and (recommended_tests_new !='' and recommended_tests_new is not null);";
$result = mysqli_query($conn, $query);
while ($row = mysqli_fetch_assoc($result)) {
$appointment_id = $row['appointment_id'];
$tests = explode(",", $row['recommended_tests_new']);
$test_ids = [];
for ($i = 0; $i < sizeof($tests); $i++) {
$test_id = getFieldFromTable('section_id', 'checkup_form_section', 'section_name', trim($tests[$i]));
if (trim($test_id) != '' && trim($test_id) != null) {
array_push($test_ids, $test_id);
}
}
if (sizeof($test_ids) > 0) {
$corrected_data = implode(",", $test_ids);
$update = "update employee_appointment set recommended_tests_new = '" . $corrected_data . "' where appointment_id = '" . $appointment_id . "'";
error_log("correction query " . $update);
if (!$result_update = mysqli_query($conn, $update)) {
error_log("error while correcting the data " . mysqli_error($conn));
}
}
}