<?php
    header('Access-Control-Allow-Origin: *');
    header('Access-Control-Allow-Methods: GET, POST');
    header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization");
    include '../config/index.php';
    $data = array();

    $tags = array();

    $sql="select * from courses    ";
    $result = mysqli_query($conn, $sql);  
    if (mysqli_num_rows($result) > 0) {
        while($row = mysqli_fetch_assoc($result)) {
            $sql1="select * from tags_courses WHERE course_id='".$row["course_id"]."'  order by dated desc limit 1 ";
            $result1 = mysqli_query($conn, $sql1);  
            if (mysqli_num_rows($result1) > 0) {
                while($row1 = mysqli_fetch_assoc($result1)) {
                    $new_array = array(
                        'id' => $i,
                        'course_id' => $row["course_id"],
                        'course_name' =>  $row["course_name"],
                        'course_image' =>   $row["course_image"],
                        'course_description' => $row["course_description"],
                        'expected_outcome' => $row["expected_outcome"],
                        'delivery_mode' =>$row["delivery_mode"],
                        'minimum_age' =>$row["minimum_age"],
                        'required_sessions' =>$row["required_sessions"],
                        'active' =>$row["active"],
                        'dated' =>$row["dated"],
                        'category' => $row["course_tags_id"]
                    );
                    array_push($data, $new_array);

                }
            }
        }
    }
    echo json_encode($data);

       
  
?>