I have a problem with a speed of mysql query. I have 2 select boxes with country and cities, on first select changes cities on the second, its provided by ajax:
$(document).ready(function()
{
$(".country").change(function()
{
var id=$(this).val();
var dataString = 'id='+ id;
function doAJAX(url) {
$.ajax
({
type: "POST",
url: url,
data: dataString,
cache: false,
success: function(html)
{
$(".city").html(html);
}
});
}
doAJAX('search_ajax.php');
});
});
When is for example spain or russia where is so many cities, showing them took too much time, table cities:fips 2 varchar, city varchar 100, my select :
SELECT city from cities where fips='some value' //for example EN or any ..
I have on column fips index.
Can anobody help mi to speed this up? or is a better solution other than ajax to make live change of select's?? thanks
The following recommendations will help you in your SQL tuning process.
You'll find 3 sections below:
ALTER TABLE `cities` ADD INDEX `cities_idx_fips` (`fips`);
SELECT
cities.city
FROM
cities
WHERE
cities.fips = 'some value'