<?php
include "db.php";

$page=$_GET['page'] ?? 1;
$search=$_GET['search'] ?? "";

$limit=12;
$offset=($page-1)*$limit;

$where="";

if($search!=""){
$where="WHERE menu_name LIKE '%$search%'";
}

$total=$conn->query("SELECT COUNT(*) as c FROM menus $where")->fetch_assoc()['c'];

$pages=ceil($total/$limit);

$result=$conn->query("SELECT * FROM menus $where LIMIT $limit OFFSET $offset");

$radios=[];

while($row=$result->fetch_assoc()){
$radios[]=$row;
}

echo json_encode([
"radios"=>$radios,
"pages"=>$pages
]);