如何重写此查询

I can't understand what is wrong with this query.

For example: From table names I want to get all records which match string Hound, like hound, Hound 1.2.3, HoundChat, hound version 5.0.2.6, HOUND ver.7.4.4(1536).

Also, string I'll get from $nameid which is associated with column name in table names.

$files = mysql_query("SELECT * FROM names WHERE name LIKE '$nameid%'") or die(mysql_error());
$i=1;  while($row=mysql_fetch_array($files)) {
echo "<a href=\"/files/$row[1]\>";
$i++;

UPDATE: I've get success with $nameid= substr($_GET['name'],0,5); Which get only 5 characters from variable and works for me.

Try as below :

$files = mysql_query("SELECT * FROM names WHERE name LIKE '".$nameid."%'") or die(mysql_error());

I assume from your question $nameid is a variable which will have the value hound. You just need to handle the case-insensitive aspect of your query.

Also, You should use prepared statements to prevent sql injection, for example with PDO:

$st = $db->prepare("SELECT * FROM names WHERE name COLLATE UTF8_GENERAL_CI LIKE ?");
$st->execute(array($nameid.'%'));

See explanation of the COLLATE part of the statement here.