Search using PHP / MySQL and dynamically update using jQuery

I was wondering how to do the best with PHP / MySQL and jQuery:

There is a basic search mask in which you enter the city and from time to time. You go to the search results page, where you can narrow the search results using certain parameters (flags, jQuery slider, text input, ...). Search results should be updated on the fly without reloading the entire page ...

I manage to use jQuery ajax and load it to send information to another php file, for example, SELECT and return the results to the search details page, but I don’t know how to combine the various changes that narrow down the search results.

In addition, the details page already has results, so I don’t need to add more results, but “delete” the results that no longer work ...

The fact is that each parameter to narrow the search is associated with another table in the database. Do I need and how to add additions to the original request ...? Or am I thinking in the wrong direction?

+3
source share
3 answers

Yes, this is absolutely the right direction. Use

$(document).ready(function() {  

    $('#ID_OF_YOUR_ELEMENT_TO_LOAD_INTO').load("load.php?parameter1=<?php echo $parameter1; ?>&parameter2=<?php echo $parameter2; ?>");

});

to get results when the user first hits the page to get results according to your city and your dates.

load.php, , , . , ( , ) , .load, :

$('#ID_OF_YOUR_FORM_BEING_UPDATED').change(function() {

    $('#ID_OF_YOUR_ELEMENT_TO_LOAD_INTO').load("load.php?parameter1=<?php echo $parameter1; ?>&parameter2=<?php echo $parameter2; ?>&parameter3=<?php echo $parameter3; ?>");

});
+2

PHP/MySQL, Javascript html, javascript .

, , html , . , .

, http://www.wowhead.com

, , .; -)

+1

SQL- .

ajax , . , . php , $_POST $_GET ($ _POST ajax , $_GET ) .

:

Javascript searchAjaxHandler.php?city=Chicago&from=2012-03-01&to=2012-03-05&someColumnLowerRange=500&someColumnUpperRange=700

php script :

$query = "SELECT * FROM Data WHERE City=? AND Date > ? AND Date < ?";
$arguments = array($_GET['city'], $_GET['from'], $_GET['to']);
if (isset($_GET['someColumnLowerRange'])) {
    $query .= " AND someColumn > ?";
    $arguments[] = $_GET['someColumnLowerRange'];
}
if (isset($_GET['someColumnUpperRange'])) {
    $query .= " AND someColumn < ?";
    $arguments[] = $_GET['someColumnUpperRange'];
}
//execute the query
//using PDOs (google them...they are a good way to prevent sql injection and
//support multiple database types without modifying code too much), create a
//statement with the above query in put the statement in $statement

$statement->execute($arguments); //this uses the $arguments array to fill in the prepared statement ?'s

//then do the stuff to get the retrieved rows out of the result returned

javascript , , .

0

All Articles