<?php
require 'db.php';

$data = [];

$res = mysqli_query($conn,"
    SELECT * FROM categories
    ORDER BY sort_order ASC
");

while($r = mysqli_fetch_assoc($res)){

    $data[] = [
        $r['id'],
        htmlspecialchars($r['name']),
        $r['slug'],
        $r['sort_order'],
        ucfirst($r['status']),
        '
        <button class="btn btn-sm btn-primary edit-btn"
            data-id="'.$r['id'].'"
            data-name="'.$r['name'].'"
            data-sort="'.$r['sort_order'].'"
            data-status="'.$r['status'].'">Edit</button>

        <button class="btn btn-sm btn-danger delete-btn"
            data-id="'.$r['id'].'">Delete</button>
        '
    ];
}

echo json_encode(['data'=>$data]);
