私はAJAX-XML-PHP Search engingeを作成しており、w3schoolsの華麗な記事を見つけました:hereしかし、私のXMLファイルは巨大で、 1つまたは2つの文字が入力されるたびに下にスクロールしてください。あなたが私が意味するものを得るなら、私は起こりたいと思うのは、PHPファイルが6つの「可能な検索」に返信することだけです。ここに私のコードは次のとおりです。XMLファイルからエコーされたAjax応答の量を制限する
<?php
$xmlDoc=new DOMDocument();
$xmlDoc->load("places.xml");
$x=$xmlDoc->getElementsByTagName('link');
//get the q parameter from URL
$q=$_GET["q"];
$counter;
//lookup all links from the xml file if length of q>0
if (strlen($q)>0) {
$hint="";
for($i=0; $i<($x->length); $i++) {
$y=$x->item($i)->getElementsByTagName('title'); //$y = title
$z=$x->item($i)->getElementsByTagName('url'); //$z = url
if ($y->item(0)->nodeType==1) {
//find a link matching the search text
if (stristr($y->item(0)->childNodes->item(0)->nodeValue,$q)) {
if ($hint=="") {
$hint="<a href='" . $z->item(0)->childNodes->item(0)->nodeValue . "' target='_blank'>" . $y->item(0)->childNodes->item(0)->nodeValue . "</a>";
} else {
$hint=$hint . "<br /><a href='" . $z->item(0)->childNodes->item(0)->nodeValue . "' target='_blank'>" . $y->item(0)->childNodes->item(0)->nodeValue . "</a>";
}
}
}
}
}
// Set output to "no suggestion" if no hint was found
// or to the correct values
if ($hint=="") {
$response="Hmm, nothing here!";
} else {
$response=$hint;
}
//output the response
echo $response;
?>
、ここでは私のXMLファイルの抜粋です:
<?xml version="1.0" encoding="UTF-8"?><places><link><title>Afghanistan</title><url>/places/Afghanistan</url></link><link><title>Albania</title><url>/places/Albania</url></link>
</places>
で終わるもちろん。
私は周りの2日間、この作業で苦労されていますし、任意のサポートは本当に役立つだろう!
注:Ajaxはうまく動作していますので、クライアント側のhtml + jsはちょうど私ができない6回の返事を得ています!
'のために($ i = 0; $ iが6 <; $ iは++しますか){'? @ SergeK。 –
残念ながら、私はすでに、および何らかの理由でそれが唯一の最初の6つのXMLノードを一覧表示することを試してみました:/ – MajorPlayz
私が理解から、あなただけの6件の結果を必要とする。.. – TamirNahum