<?php
function get_job_categories() {
    global $conn;
    $cats = [];
    $sql = "SELECT name FROM job_categories ORDER BY name ASC";
    $result = $conn->query($sql);
    if ($result) {
        while($row = $result->fetch_assoc()) {
            $cats[] = $row['name'];
        }
    }
    // Fallback if empty or error
    if (empty($cats)) {
        return ["Masons", "Carpenters", "Plumbers", "Electricians", "Other"];
    }
    // Ensure 'Other' is always at the end if it exists
    if(($key = array_search('Other', $cats)) !== false) {
        unset($cats[$key]);
        $cats[] = 'Other';
    } else {
        $cats[] = 'Other';
    }
    
    return $cats;
}
?>
