A
A
ash_12014-10-16 18:05:06
PHP
ash_1, 2014-10-16 18:05:06

Display cities from mysql by first letter, how to do?

I have mysql database of city and country. 1000000 records
I'm looking for a city for example Moscow, I make a request to the database, get me 10 cities.
There is a text input when you click on each letter, an Ajax request occurs where the data from this field is sent to the server. That is, first I press "M" there is a request, he pulls me out of the database of 10 cities that contain the letter "M". It turns out that it displays such cities as Abakumovo, Abakumovskaya and so on. As you can see, the first letter in cities is "A", not "M".
I want that when the "M" button is pressed, cities starting with M are displayed. For example, Moscow, Mozhaisk, etc.
Then I press, for example, "Mo", displays cities starting with Mo from the database, and so on
. Or do I need to process the list with php code? and then print?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Borovikov, 2014-10-16
@ash_1

Something like this
$query_cities = "SELECT * FROM `cities` WHERE `cities`.`name` LIKE '".escape($_GET['text'])."%' LIMIT 10";

D
Dmitry Skogorev, 2014-10-16
@EnterSandman

ajax live search
ajax autocomplete
ninetofive.me/blog/build-a-live-search-with-ajax-p...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question