Enable filtering mode problem

Hi first of all thx for taking time reading this.
Second, when using the combo_firm_name.enableFilteringMode(true,“/phpmyadmin/research_invoice_combo.php”,true);
we get problems when we want to get results.

This is what should happen.
First example:
user types in “Solutions”
Result should be “Ilias Solutions” and other frim names containing Solutions

next example
user types in “tra”
Result should be “Eltrabel” and other frim names containing tra

What we tried so far.
It work perfect when whe filter from first letter. We only have to type in 2 letters and we get a nice result.

When we try to use the filter when the name contains the mask whe get strange results.
First example:
user types in “Solutions”
Result “no results”

next example
user types in “tra”
Result “no result” until we type in “trabe”

next example
user types in “zh”
Result “Zhendre”

We tried to find out why we get sometimes results with 2 letters, Sometimes we need 4 or More and sometimes we get no result.
Sadly we are stuck.
Any help would be nice.

ps there are about 15.1K different firms
Here is the php file.

<?php header("Content-type: text/xml"); $xml = '<?xml version="1.0" encoding="UTF-8"?>'.

function p($s) {
	if (!get_magic_quotes_gpc()) return mysql_real_escape_string($s);
	return $s;

//Here we set connection and database and test if all is oke.

if (!isset($_REQUEST["pos"])) $_REQUEST["pos"]=0;

$mask = @$_REQUEST["mask"];
$pos = @$_REQUEST["pos"];
if (!is_numeric($pos)) $pos = 0;

$res = mysql_query("SELECT distinct name 
	FROM local_research_invoice WHERE LOWER(name) LIKE LOWER('".p($mask)."%') ORDER BY name LIMIT ".p($pos).", 40");
while ($row = mysql_fetch_array($res)) $xml .= '<option value="'.$row["name"].'">'.$row["name"].'</option>';

$xml .= '</complete>';



a) your SQL query, if you want to filter by text at any position, isn’t it must be LIKE LOWER(’%".p($mask)."%’) ?
b) the data in the DB. It possible that while filtering by two letters, the result dataset contains some records with problematic data ( data which corrupts the result XML. It can be a data in the wrong encoding or a data which contains some XML special chars and need to be escaped before outputing as XML ) You can try to check the result of server side script in the debug console of a browser. In the case of invalid XML, there will be info about offending characters.