<?php


// Database connection parameters

$servername = "localhost";

$username = "username";

$password = "password";

$database = "your_database";


// Create connection

$conn = new mysqli($servername, $username, $password, $database);


// Check connection

if ($conn->connect_error) {

    die("Connection failed: " . $conn->connect_error);

}


// Select all records from tbl_booking_details

$sql = "SELECT tbl_booking_details_primary_id, actual_end_date FROM tbl_booking_details";

$result = $conn->query($sql);


if ($result->num_rows > 0) {

    // Loop through each row in tbl_booking_details

    while ($row = $result->fetch_assoc()) {

        $booking_id = $row['tbl_booking_details_primary_id'];

        $actual_end_date = $row['actual_end_date'];


        // Check if actual_end_date is different in tbl_booked_car_details

        $check_sql = "SELECT allocation_to_date FROM tbl_booked_car_details WHERE tbl_booking_details_primary_id = $booking_id";

        $check_result = $conn->query($check_sql);


        if ($check_result->num_rows > 0) {

            $check_row = $check_result->fetch_assoc();

            $allocation_to_date = $check_row['allocation_to_date'];


            // If actual_end_date is different, update allocation_to_date

            if ($allocation_to_date != $actual_end_date) {

                $update_sql = "UPDATE tbl_booked_car_details SET allocation_to_date = '$actual_end_date' WHERE tbl_booking_details_primary_id = $booking_id";


                if ($conn->query($update_sql) === TRUE) {

                    echo "Record updated successfully for booking ID: $booking_id\n";

                } else {

                    echo "Error updating record: " . $conn->error . "\n";

                }

            }

        }

    }

} else {

    echo "0 results found in tbl_booking_details\n";

}


$conn->close();


?>


Comments

Popular posts from this blog

How to seperate character from string in php

How to Delete record using PHP Ajax

Uploads Only 10 files in month step by step