Сделал по книге используя prototype.js... но иначе...
Код | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <meta http-equiv="Content-Language" content="ru"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>AJAX PHP search example - Prototype</title> <link rel="stylesheet" href="style.css" type="text/css"> <script src="inf.js" type="text/javascript"></script> <script src="prototype.js" type="text/javascript"></script> </head> <body>
<form onsubmit="streetform(); return false;"> <input type="text" class="input" id="street" value=""> <input type="submit" class="button" id="search_button" value="» поиск"> </form> <!-- поле для вывода найденных улиц --> <div id="street_results"> </div><br> <div id='house_results'></div> <!-- временный слой типа Ищу --> <div id="searching" style="display: none">Поиск...</div>
</body> </html>
|
Код | function streetform(){ var sSearch = $F("street"); $('street_results').hide(); $('searching').show();
new Ajax.Updater('street_results', 'search.php?q=q1', { method: 'get', parameters: { search: sSearch }, onComplete: function () { $('street_results').show(); $('searching').hide(); } } ); }
function houseform() { var sSearch = $F("house"); $('house_results').hide(); $('searching').show();
new Ajax.Updater('house_results', 'search.php?q=q2', { method: 'get', parameters: { houses: sSearch }, onComplete: function () { $('house_results').show(); $('searching').hide(); } } ); }
|
Код | <?php $db = mysql_connect("localhost", "Suf", "111"); mysql_select_db("ll"); mysql_query("SET CHARACTER SET utf8"); header('Content-type: application/xml; charset=utf-8'); header('Cache-Control: no-cache');
if($q == "q1"){ $sString = $_GET["search"]; $sql="SELECT * FROM streets WHERE street LIKE '%$sString%'"; $rs=mysql_query($sql,$db); echo "<form onsubmit='houseform(); return false;'>"; while ($row = mysql_fetch_array($rs)) {
$val = $row[street]; echo $val; echo "<input type='submit' class='button' id='house' value='$val'>$val - <br>"; } echo "</form>"; echo ""; }
if($q =="q2"){ $sString = $_GET["houses"];
$sql="SELECT * FROM houses WHERE street ='$sString'"; $rs=mysql_query($sql,$db); while ($row = mysql_fetch_array($rs)) { echo "$row[house] - $sString<br>"; } } ?>
|
Но проблема в том, что после вывода всех улиц, при проверке домов используется улица, выведенная первой... |