false, 'data' => null, 'message' => ''); try { $pdo = db_connect(); // 품목 검색어가 있는 경우 if (!empty($search_keyword)) { $sql = "SELECT num, itemName, item_spec, material, search_keyword, item_bending, exit_direction, front_bottom_width, rail_width, box_width, box_height FROM {$DB}.bending WHERE search_keyword LIKE :search_keyword ORDER BY num DESC LIMIT 1"; $stmh = $pdo->prepare($sql); $stmh->bindValue(':search_keyword', '%' . $search_keyword . '%'); $stmh->execute(); $row = $stmh->fetch(PDO::FETCH_ASSOC); if ($row) { $response['success'] = true; $response['data'] = $row; $response['message'] = '품목검색어로 검색된 결과입니다.'; } else { $response['message'] = '품목검색어로 검색된 결과가 없습니다.'; } } // 품목 검색어가 없는 경우 - 조건별 검색 (품목명은 '셔터박스'로 고정) else { // 규격을 120*70 형태로 변환 $formatted_spec = ''; if (!empty($item_spec)) { // 기존 규격에서 가로*세로 형태로 변환 // 예: 120*70 형태로 변환 $formatted_spec = $item_spec; } // 조건별 검색 쿼리 구성 (절곡그룹은 찾기) $where_conditions = array("item_bending = :item_bending"); $params = array(':item_bending' => $item_bending); if (!empty($exit_direction)) { $where_conditions[] = "exit_direction = :exit_direction"; $params[':exit_direction'] = $exit_direction; } if (!empty($front_bottom_width)) { $where_conditions[] = "front_bottom_width = :front_bottom_width"; $params[':front_bottom_width'] = $front_bottom_width; } if (!empty($rail_width)) { $where_conditions[] = "rail_width = :rail_width"; $params[':rail_width'] = $rail_width; } if (!empty($box_width)) { $where_conditions[] = "box_width = :box_width"; $params[':box_width'] = $box_width; } if (!empty($box_height)) { $where_conditions[] = "box_height = :box_height"; $params[':box_height'] = $box_height; } // 추가 검색 조건들 if (!empty($material)) { $where_conditions[] = "material = :material"; $params[':material'] = $material; } if (!empty($itemName)) { $where_conditions[] = "itemName = :itemName"; $params[':itemName'] = $itemName; } $sql = "SELECT num, itemName, material, search_keyword, item_bending, exit_direction, front_bottom_width, rail_width, box_width, box_height FROM {$DB}.bending WHERE " . implode(' AND ', $where_conditions) . " ORDER BY num DESC LIMIT 1"; $stmh = $pdo->prepare($sql); // 파라미터 바인딩 foreach ($params as $key => $value) { $stmh->bindValue($key, $value); } $stmh->execute(); $row = $stmh->fetch(PDO::FETCH_ASSOC); if ($row) { $response['success'] = true; $response['data'] = $row; $response['message'] = '조건별 검색으로 찾은 결과입니다.'; } else { $row['num'] = ''; $response['data'] = $row; $response['success'] = false; $response['message'] = '조건에 맞는 결과가 없습니다.'; } } } catch (PDOException $e) { $response['message'] = '검색 중 오류가 발생했습니다: ' . $e->getMessage(); } // JSON 응답 header('Content-Type: application/json; charset=utf-8'); echo json_encode($response, JSON_UNESCAPED_UNICODE); ?>