get($_SESSION['id']); $regionRfId = $curUser->region_rf_id; } $cldr = 'rf_region_id = ' . $regionRfId; if($regionRfId == 1 || $regionRfId == 2 || $regionRfId == 3) { $cldr = '(rf_region_id in (select id from rf_regions where parent = ' . $regionRfId . '))'; } if ($search == null) { $sqlCount = "SELECT count(id) FROM newbuildings where ". $cldr ." ORDER BY name, ID"; } else { $sqlCount = "SELECT count(id) FROM newbuildings WHERE ". $cldr ." and name like '%" . trim($search) . "%' ORDER BY name, ID"; } $rez = mysql_query($sqlCount); $allCount = mysql_result($rez, 0); $all_pages = ceil($allCount / $numberOfRecords); $ot = ($page - 1) * $numberOfRecords; if ($search == null) { $sql = "SELECT * FROM newbuildings where ". $cldr ." ORDER BY name, ID LIMIT $ot, $numberOfRecords"; $rez = mysql_query($sql); while ($block = mysql_fetch_assoc($rez)) { $blockList[] = $block; } } else { $sql = "SELECT * FROM newbuildings WHERE ". $cldr ." and name like '%" . trim($search) . "%' ORDER BY name, ID LIMIT $ot, $numberOfRecords"; $rez = mysql_query($sql); while ($block = mysql_fetch_assoc($rez)) { $blockList[] = $block; } } $response = []; $response['items'] = array(); $response['total_count'] = $allCount; // Read Data foreach ($blockList as $block) { $response['items'][] = array( "id" => $block['id'], "text" => $block['name'] ); } echo json_encode($response); exit();