<?php
session_start();  
include("configa.php");  // ডাটাবেস কানেকশন কনফিগ

header('Content-Type: application/json');

$q = isset($_GET['q']) ? $_GET['q'] : '';
$q = $conn->real_escape_string($q);

if(strlen($q) < 2){
  echo json_encode([]);
  exit;
}

$sql = "SELECT id, holdingNo, ward, name, fatherHusband, homeName, address, mobile, pesha, khanarDhoron, khanarMullo, purus, chele, mohila, meye, korAropMullo, tofsileeKor, bokeya, bokeyaPorishod
        FROM holding_form
        WHERE holdingNo LIKE '%$q%' OR name LIKE '%$q%'
        LIMIT 100";

$result = $conn->query($sql);

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

echo json_encode($records);
$conn->close();
