使用PHP在SQL中搜索第一个字母

Alright so I made this little script that runs and checks where some name contains character that user inputed. So for example if I enter "A" it will show me ALL users that have "A" as part of their name (Admin, Toma) etc. etc. Now what I want to achieve is quite simple, I want of it to select only characters that START with that letter. So for example imagine I type in A it will display me only Admin and NOT Toma since TOMA starts with T.

Current query

query("SELECT ime FROM users WHERE ime LIKE '%".$term."%'")

Do you suggest that I use PHP to achieve this or directly do this with a query?

If so let me know what is the best way, thank you in advance!

Your query should just remove the initial wildcard:

"SELECT ime FROM users WHERE ime LIKE '".$term."%'"

Try this :

SELECT ime FROM users WHERE ime LIKE '".$term."%'"

Remove the '%' wildcard character from the beginning of the LIKE comparison. That wildcard character matches zero, one or more of any character.

As a demonstation

SELECT 'Toma' LIKE '%A%'        -- contains an 'A'
     , 'Toma' LIKE 'A%'         -- starts with 'A'
     , 'Toma' LIKE 'Toma'       -- matches 'Toma'
query("SELECT ime FROM users WHERE ime LIKE '".$term."%'")

Just remove the the first % Please check this http://www.w3schools.com/sql/sql_like.asp for more info