1

I want to combine the variable $name with the "%" so i can search for names that begin the value of $name.

$name = $_POST['name'];
$get_search_results_q= "SELECT * FROM `users`.`info` WHERE `info`.`fullname` ='$name'+'%' ";
1
  • What's wrong with ='".$name."%'? Commented Sep 1, 2014 at 18:50

2 Answers 2

4

This u need

$get_search_results_q= "SELECT * FROM `users`.`info` WHERE `info`.`fullname` LIKE '$name%' ";
Sign up to request clarification or add additional context in comments.

4 Comments

Worked as expected!Thanks mate :)
Why it returns nothing when i type something that doesn't exist in DB?
because its only return if found any record that begin as u defined LIKE 'keyword%' for all record begin 'keyword'
No i mean nothing.mysql_query doesn't show anything.It don't return even false...
2
$get_search_results_q= "SELECT * FROM `users`.`info` WHERE `info`.`fullname` ='$name%' ";

Note that your code is open to SQL injection, you should have a look at prepared statements.

1 Comment

I know Ende thanks for the reply.At the moment i build the main idea,later i will go to mysqli()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.