I want to check a row in an mysql table for the username in php, if the username starts with ab to write an text.
the username is in a cell开发者_StackOverflow and looks like this: ab_12345453.
Thanks, Sebastian
EDIT:
thank you all for your reply.
but i need something else.
i need this for joomla, i don't need to make an query, i just use: $user->username
and i get the logged in username.
so i have the logged in username in a variable. how can i check that the username starts with ab_ ?
thank you again and sorry for the confusion :(
SELECT * FROM bar B where B.username LIKE 'ab%';
See the manual here.
I vote for Artefacto's solution, and add to it a recommendation:
alter table bar add key(username(2));
In case you don't have an index for the column.
use can use also substring
http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_substring
Use LIKE command with single % wildcard to say anychar
SELECT * FROM table WHERE col LIKE 'ab%';
精彩评论