Path : /var/www/html/smart_kpp2_bk17 มีค 69/blocks/
File Upload :
Current File : /var/www/html/smart_kpp2_bk17 มีค 69/blocks/block-affair.php

<?php
$today = date("Y-m-d");

// ดึงข้อมูลตั้งแต่วันนี้เป็นต้นไป
$sql = "SELECT affair_main.*, person_main.*, affair_main.id 
        FROM affair_main 
        LEFT JOIN person_main 
        ON affair_main.operation_person = person_main.person_id 
        WHERE affair_main.affair_date >= '$today'
        ORDER BY affair_main.affair_date ASC, affair_main.affair_time ASC
        LIMIT 5";

$dbquery = mysqli_query($connect,$sql);
$num_rows = mysqli_num_rows($dbquery);

if ($num_rows != 0){

    echo "<br><h5 style='color:red;'>&nbsp;&nbsp;&nbsp; ภารกิจผู้อำนวยการสำนักงานเขตพื้นที่การศึกษา</h5>";

    echo "<ol>";

    while ($result = mysqli_fetch_array($dbquery)){

        echo "<font size=2><li>";
        //echo "<font size=2 color='#1303c6ff'>" . thai_date_3($result['affair_date'])."</font>";
       

$start = $result['affair_date'];
$end   = $result['affair_date_end'];

echo "<font size=2 color='#1303c6ff'>";

if (!empty($start) && !empty($end)) {

    $start_ts = strtotime($start);
    $end_ts   = strtotime($end);

    $start_day   = date("j", $start_ts);
    $end_day     = date("j", $end_ts);
    $start_month = date("n", $start_ts);
    $end_month   = date("n", $end_ts);
    $start_year  = date("Y", $start_ts) + 543;
    $end_year    = date("Y", $end_ts) + 543;

    $thai_month = [
        1=>"มกราคม",2=>"กุมภาพันธ์",3=>"มีนาคม",4=>"เมษายน",
        5=>"พฤษภาคม",6=>"มิถุนายน",7=>"กรกฎาคม",8=>"สิงหาคม",
        9=>"กันยายน",10=>"ตุลาคม",11=>"พฤศจิกายน",12=>"ธันวาคม"
    ];

    if ($start == $end) {
        echo $start_day . " " . $thai_month[$start_month] . " " . $start_year;
    } 
    elseif ($start_month == $end_month && $start_year == $end_year) {
        echo $start_day . "–" . $end_day . " " . 
             $thai_month[$start_month] . " " . $start_year;
    } 
    elseif ($start_year == $end_year) {
        echo $start_day . " " . $thai_month[$start_month] . 
             " – " . 
             $end_day . " " . $thai_month[$end_month] . 
             " " . $start_year;
    } 
    else {
        echo $start_day . " " . $thai_month[$start_month] . " " . $start_year .
             " – " .
             $end_day . " " . $thai_month[$end_month] . " " . $end_year;
    }

} elseif (!empty($start)) {

    echo thai_date_3($start);

} elseif (!empty($end)) {

    echo thai_date_3($end);

}
// ถ้าว่างทั้งคู่จะไม่แสดงอะไรเลย

echo "</font>";


        echo "<font size=2> - ";
        echo "<font size=2>".$result['subject'];
        echo "<font size=2> " . $result['location']. "</font>";
        echo "</li>";
    }

    echo "</ol>";

}else{
    echo "<h5 style='color:red;'>ภารกิจผู้อำนวยการสำนักงานเขตพื้นที่การศึกษา</h5>";
    echo "- ไม่มีข้อมูล - ";
}
?>