true, 'field' => null]); exit; } $iddatadb = (int)$_GET['iddatadb']; $db = DBHandlerSelect::getInstance(); $pdo = $db->getConnection(); // 1) prendo templateid da datadb // 2) cerco max 1 record in template_mapping con is_visible_parts=1 $sql = " SELECT tm.field_id, tm.field_label, tm.data_type, tm.has_list FROM datadb d JOIN template_mapping tm ON tm.template_id = d.templateid WHERE d.iddatadb = ? AND tm.is_visible_parts = 1 ORDER BY tm.id ASC LIMIT 1 "; $stmt = $pdo->prepare($sql); $stmt->execute([$iddatadb]); $row = $stmt->fetch(PDO::FETCH_ASSOC); echo json_encode([ 'success' => true, 'field' => $row ? $row : null ]); } catch (Throwable $e) { echo json_encode(['success' => false, 'message' => $e->getMessage()]); }