index.php
最初は場所、次に検索クエリの2種類のクエリがあるページがあります。ロケーションクエリでajaxを使用しています
html構造:
<ul class="dropdown">
<li><a href="?loc=dc">City</a></li>
<li><a href="?loc=dn">North</a></li>
<li><a href="?loc=ds">South</a></li>
</ul>
<form action="" method="post">
<input type="text" name="search" id="search">
</input value="submit" type="submit"/>
</form>
<div id="content_from_AJAX">
<ul id="li_start">
</ul>
</div>
ajax.js
コード:
$(document).ready(function(e) {
function getLoc(param){
if(window.XMLHttpRequest){
xmlhttp = new XMLHttpRequest();
}
else{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function(){
if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
document.getElementById("li_start").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET","getresult.php"+param,false);
xmlhttp.send();
}
//handle anchor clicks
$("ul#location li a").click(function(){
var loc = $(this).attr("href");
getLoc(loc);
return false;
});
});
コードgetresult.php
:
require ('connect_to_mysql.php');
if(isset($_GET['loc']) && empty($_GET['loc'])===false){
$loc = mysql_real_escape_string($_GET['loc']);
$query = "SELECT * FROM TB_name WHERE loc=";
}
else{
$query = "SELECT * FROM TB_name";
}
$query_run = mysql_query($query);
$count = mysql_num_rows($query_run);
if($count<1){
echo 'no result found';
}
else{
while($result == mysql_fetch_assoc($query_run)){
echo "ALL results";
}
// Here is what I want to be able o access on index.php
return $_GET['loc']
}
に$_GET
アクセスしindex.php
て、上記のフォームの検索クエリの結果をフィルタリングするために使用できるようにします。
"SELECT * FROM `TB_name` WHERE `keyword` LIKE '$keyword' AND `loc`='".$_GET['loc']."'"
index.php
//これをオンではなくオンにする必要がありますgetresult.php
またAJAX.js
、ユーザーがissetの場合にlocリンクをクリックした場合に、getresult.phpでクエリを送信する必要があります$_POST['search']
。
このプロジェクトが本当に必要になるのを手伝ってください、そして私はとても落ち込んでいますX_X..助けてくれてありがとうございます:)