fxEscape($strTable) . "' AND lab_code = '" . $GLOBALS['db']->fxEscape($strField) . "'"; $tabAutocomplete = $GLOBALS['db']->fxGetRow($sqlAutocomplete); $sqlSearch = $tabAutocomplete['lab_list']; if ($tabAutocomplete['lab_autocomplete_where'] != '') $sqlSearch .= " WHERE " . $tabAutocomplete['lab_autocomplete_where']; else $sqlSearch .= " WHERE 1 = 1"; $tabSearchFields = explode(',', $tabAutocomplete['lab_autocomplete_search']); $intNbFields = count($tabSearchFields); foreach ($tabParts as $strSearch) { if ($intNbFields > 1) { for ($intCtr = 0; $intCtr < $intNbFields; $intCtr++) { if ($intCtr === 0) $sqlSearch .= " AND ("; $sqlSearch .= $strField . " LIKE " . "'%" . $GLOBALS['db']->fxEscape($strSearch) . "%'"; if (($intCtr + 1) < $intNbFields) $sqlSearch .= " OR "; else $sqlSearch .= ")"; } } else $sqlSearch .= " AND " . $tabSearchFields[0] . " LIKE " . "'%" . $GLOBALS['db']->fxEscape($strSearch) . "%'"; } $tabSearch = $GLOBALS['db']->fxGetResults($sqlSearch); if ($tabSearch === false) { $user_error = 'Wrong SQL: ' . $sqlSearch; trigger_error($user_error, E_USER_ERROR); } $tabJson = array(); for ($intCtr = 1; $intCtr <= count($tabSearch); $intCtr++) { $tabJson[] = array('id' => fxUnescape($tabSearch[$intCtr]['id']), 'label' => fxUnescape($tabSearch[$intCtr]['label']), 'value' => fxUnescape($tabSearch[$intCtr]['value'])); } $strJson = json_encode($tabJson); print $strJson; ?>