tags:

views:

45

answers:

4

Hi. I wish to make so when you search e.g "A" then every full_name with beginning "A" will appear. So if a user with name "Andreas blabla" will show

I have this right now:

$query = "SELECT full_name, id, user_name, sex, last_access, bostadsort 
              FROM users WHERE full_name LIKE '$_GET[searchUser]'"; 

But still i need to search "Andreas blabla" in order to get him out the query(show). So this doesnt work.

How can i do this?

+1  A: 

Use MySql wildcards like:

$query = "SELECT full_name, id, user_name, sex, last_access, bostadsort FROM users WHERE full_name LIKE '$_GET[searchUser]%'";

fabrik
+4  A: 

Use the % meta character after the input character in the LIKE comparison:

$query = " … WHERE full_name LIKE '$_GET[searchUser]%'";

And don’t forget to validate the input or escape the output properly when inserting it into the query.

Gumbo
A: 

Use:

...LIKE '$_GET[searchUser]%'"; 

If the user searches for A, this will select all rows where full_name begins with an A

% is a wild card to match anything.

codaddict
+2  A: 

It seems complete code would be better than just comment

$search = mysql_real_escape_string($_GET['searchUser']);
$query = "SELECT full_name, id, user_name, sex, last_access, bostadsort 
          FROM users WHERE full_name LIKE '$search%'"; 
Col. Shrapnel