-1
我有我想要搜索的使用值和键多维数组PHP多维数组这如何搜索使用AJAX
<input type="text" onkeyup="showHint(this.value)"></input>
与此
function showHint(str)
{
if (str.length==0)
{
document.getElementById("nav").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("nav").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","gethint.php?q="+str,true);
xmlhttp.send();
}
沿着我只是一个位卡在了PHP位。该阵列看起来像这样(缩短)
Array
(
[Modest Mouse] => Array
(
[The Moon & Antarctica] => Array
(
[0] => 3rd Planet
[1] => Gravity Rides Everything
[2] => Dark Centre of the Universe
)
[The Lonesome Crowded West] => Array
(
[7] => Cowboy Dan
[8] => Trailer Trash
[9] => Out of Gas
)
[The Vasco Era] => Array
[Lucille] => Array
(
[0] => Not Stuck Here
[1] => For No One
)
)
)
我开始通过获取查询
$q=$_GET["q"];
然后,我可以做到这一点
if (strlen($q) > 0)
{
$hint="";
foreach($a as $b => $c)
{
if (strtolower($q)==strtolower(substr($b,0,strlen($q))))
{
if ($hint=="")
{
$hint=$b;
}
else
{
$hint=$hint." , ".$b;
}
}
}
}
这可以让我谦虚鼠标或瓦斯科时代,但没有更深层次的东西。如果我想在输入字段中输入'T',我希望能够得到'月球& Antartica','寂寞拥挤西部','Trailer Trash'和'The Vasco Era'的结果。
我无法完成它的工作,但你已经把我放在正确的轨道上,我应该能够从这里得到它谢谢你 – clethers 2013-02-21 04:06:19