tags:

views:

56

answers:

4

Hi,

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 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 :(

+5  A: 
SELECT * FROM bar B where B.username LIKE 'ab%';

See the manual here.

Artefacto
A: 

Use LIKE command with single % wildcard to say anychar

SELECT * FROM table WHERE col LIKE 'ab%';

RobertPitt
_ is a wildcard too
Naktibalda
Oh right, never knew that :)
RobertPitt
A: 

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.

ceteras