Hey All, I am trying to write a php script and would like to have an autosuggest text box with data from a mysql database. This would be for designating a town in a form.
The sql query I would use would be.

$sql = "SELECT DISTINCT `Town` FROM '".$Table_Name."' ";

Then there would be a second autosuggest text box that would only select cemeteries in the town from the first box.

I have found a few tutorials on the web but can't seem to get them to work with a sql query.

Does anyone have any suggestions???

10 Years
Discussion Span
Last Post by noufal68

Your syntax is not quite right in the SQL statement. You don't need so many quote marks. This will work for you I believe:

$sql = "SELECT DISTINCT Town FROM $Table_Name";

Then you actually need to run the query. What I normally do is use the PDO library to connect to a MySQL database, but there are other ways of doing it too. Here is a link to the PDO documentation. If you have trouble connecting to your database or running the query, repost and will try to help.


I guess I should stress that I havn't got a script working yet. Could you reccomend a script to use?
I am not familiar with the PHP PDO library so I am hesitant to use it. I can get the sql query to work ok for echoing to a html based page, but I cant get it to work with a autosuggest text box. The script that I have been trying to use is HERE

Right now I use the following definitions to connect to the database.

$server //this is the host server not localhost on my server

$dbusername //the user name

$dbpassword //the password

$db_name // the name of the database

I thought this might help if someone can get a script working. I would appreciate it if you or anyone could help.


just to let you know. I did try the sql statement that you posted and it still didn't work.
I could get the script woking with a static list from the example, but when I changed things to use the sql it won't work.


Dear friend,

i have one Auto suggest. my problem with this is that i cannot navigate through

the listed items using the up down arrow keys. i tried many code to solve this

if u have idea of how this is get solved pleaSE give it to me. my mail id is [removed]

than x in advance

Edited by Ezzaral: Removed email address. Keep it on site.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.