0

I need one help.I need to get data while user is typing letter inside text field from database using PHP and MySQL.I am explaining my code below.

$searchData=$_GET['search'] ;

In the above line user is getting the letter typed by user and once one letter will be typed the according to key word search the data will fetch from data base.I am explaining the table below.

db_name:

id    name     status

1      Raj      1    

2      Rahul     1   

3      Dog       1

4      Deer      1

Suppose user typed the the first letter R the all two names belongs to R should display and the single name will come when full name will be typed.Please help me to resolve this problem.

2

2 Answers 2

0

Here is what you are looking for

http://www.bewebdeveloper.com/tutorial-about-autocomplete-using-php-mysql-and-jquery

Sign up to request clarification or add additional context in comments.

Comments

0

Try MySql fulltext search, it should do the job. here is a bit of code that i have used in one of my project.

    function getMemberIdByName($query)
    {
        //global mysql connection
        global $connection;

        $searchData = $query."*";

            $sql = "
                    SELECT 
                        * 
                    FROM 
                        member_table 
                    WHERE 
                        MATCH(name) AGAINST (:searchData IN BOOLEAN MODE) 
                    LIMIT 10
                    ";
            $statement = $connection->prepare($sql);
            $statement->bindValue(':searchData', $searchData);
            $statement->execute();
            $result = $statement->fetchAll(PDO::FETCH_ASSOC);
            if (count($result) > 0) {
                return $result;
            } else {
                return null;
            }
    }

now use jquery ajax to call call this script with POST or GET value and call this function with the search value as a parameter.

you should be able to figure out the ajax part yourself.

Comments

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.