csrtechnew.ohctech.in/get_activities.php
2025-04-14 13:28:09 +05:30

51 lines
2.0 KiB
PHP

<?php
// Include the database connection file
include 'includes/config/config.php'; // Adjust the path as necessary
// Check if the connection is successful
if (!$conn) {
error_log("Database connection failed");
die("Connection failed: " . mysqli_connect_error());
}
// Check if program_id is set via POST
if (isset($_POST['program_id'])) {
$program_id = $_POST['program_id'];
// First, fetch the activity ids associated with the selected program
$query = "SELECT activity FROM csr_program WHERE csr_id = ?";
if ($stmt = $conn->prepare($query)) {
$stmt->bind_param("i", $program_id); // Bind program_id as an integer
$stmt->execute();
$stmt->bind_result($activity_ids);
$stmt->fetch();
$stmt->close();
// Check if activity_ids is not empty
if (!empty($activity_ids)) {
// Prepare the next query to fetch activity details based on the IDs
$query_activities = "SELECT program_id, program_name FROM program_master WHERE program_id IN ($activity_ids) AND FIND_IN_SET('2', involved_process)";
error_log("Check_activity_query : ".$query_activities);
if ($result = $conn->query($query_activities)) {
// Create the options for the activity dropdown
$activity_options = "<option value=''></option>";
while ($row = $result->fetch_assoc()) {
$activity_options .= "<option value='" . $row['program_id'] . "'>" . $row['program_name'] . "</option>";
}
echo $activity_options; // Return the dropdown options
} else {
error_log("Error fetching activities: " . $conn->error);
}
} else {
echo "<option value=''>No activities found</option>";
}
} else {
error_log("Prepare statement failed: " . $conn->error);
}
} else {
echo "<option value=''>Invalid request</option>";
}
?>