Hi.
I am currently creating a type of "classifieds" website, and when the user enters the site he/she is able to choose for example "Vehicles" in a dropdown list, and then choose mileage, year, price range etc...
Here is my problem, I have managed to make contact with a db using ajax to call a php script which then checks the mysql db for the search criteria and returns a result. BUT, I need to make this as "smart" as possible...
How can i make a function or maybe a loop to check what category the user chose, and then to see if the user made any specifications on price or mileage for example, and then build a query_string to send to the php code, which then checks the mysql database for the search?
Heres a bit of code from the ajax file:
//Browser Support Code function ajaxFunction(){ var ajaxRequest; // The variable that makes Ajax possible!
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
var ajaxDisplay = document.getElementById('cont');
ajaxDisplay.innerHTML = ajaxRequest.responseText;
}
}
var category = document.getElementById('nav_category_list').value;
var city = document.getElementById('nav_city_list').value;
var querystring = document.getElementById('nav_querystring').value;
var cars_price_from = document.getElementById('cars_price_from').value;
var cars_price_to = document.getElementById('cars_price_to').value;
var cars_year_from = document.getElementById('cars_yr_from').value;
var cars_year_to = document.getElementById('cars_yr_to').value;
var cars_mileage_from = document.getElementById('cars_mile_from').value;
var cars_mileage_to = document.getElementById('cars_mile_to').value;
var cars_grbx = document.getElementById('cars_grbx').value;
var cars_fuel = document.getElementById('cars_fuel').value;
var send_query = "?category=" + category + "&city=" + city + "&cars_price_from=" + cars_price_from + "&cars_price_to=" + cars_price_to + "&cars_year_from=" + cars_year_from + "&cars_year_to=" + cars_year_to + "&cars_mileage_from=" + cars_mileage_from + "&cars_mileage_to=" + cars_mileage_to + "&cars_grbx=" + cars_grbx + "&cars_fuel=" + cars_fuel +"&querystring=" + querystring;
ajaxRequest.open("GET", "bincgi/ajax-example.php" + send_query, true);
ajaxRequest.send(null);
}