Search code examples
phpmysqlpdotextfielddynamic-data

How to create a dynamic textfield in PHP / PDO?


I have a website where I need users to interact with other users. So far all done in JQuery / Jquery Mobile and PHP with a MySQL database.

Users need to select other users to play against in a game, but may not know their exact username.

What I would like is a dynamic textfield that searches the usertable in the DB, and pulls back usernames that match the letters in the search field, so for example a user types:

S-A-M and the textfield returns all the relevant users from the DB, SamSmith, SamJones, SamBlah, then as the user types


Solution

  • Yhat you're looking for is called "autocomplete"

    You could do it yourself, however there are some plugins already developed to help you with that.

    http://jqueryui.com/demos/autocomplete/

    You'd still need to code the query to get the user list on the server side.

    Hope this helps