gene99 Posted November 18, 2009 Share Posted November 18, 2009 Sorry for double posting. My first time here. I found the PHP Ajax Live Search code here > http://www.w3schools.com/php/php_ajax_livesearch.asp I edited an rss/xml feed for recent listings from a php directory I use the same as the links.xml file example they give & got it working > http://www.easysavannah.com/livesearch.html Problem is I cannot get it to search the "description", only the "title" & "url". The "livesearch.php" listed here >> http://www.w3schools.com/php/php_ajax_livesearch.asp seems to mirror in ways the php for the MSN Live Search API code > http://dev.live.com/blogs/livesearch...01/08/445.aspx w3school's code snippet: Quote: $hint=""; for($i=0; $i<($x->length); $i++) { $y=$x->item($i)->getElementsByTagName('title'); $z=$x->item($i)->getElementsByTagName('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>"; MSN Live Search php snippett: Quote: echo('<li class="resultlistitem"><a href="' . $value->childNodes->item(2)->nodeValue . '">'); //Url echo('<h3>' . $value->childNodes->item(0)->nodeValue . '</h3></a>'); //Title echo('<p>' . $value->childNodes->item(1)->nodeValue . '</p>'); //Description } echo("</ul>"); I've tried a multitude of ways to add an echo into "w3"s code for allowing the code to search a description in an xml page. Has anyone seen a solution for this? Any help would be appreciated. Thanks, Gene PS. Code sample on index page of directory I'm testing > http://www.easysavannah.com/index2.html (middle below header) Quote Link to comment https://forums.phpfreaks.com/topic/182074-solved-sorry-for-double-posting-php-live-search-code-question/ Share on other sites More sharing options...
MadTechie Posted November 19, 2009 Share Posted November 19, 2009 Its kinda unclear what your asking for, it sounds like you want to parse a XML, Can you provide an XML sample/link Quote Link to comment https://forums.phpfreaks.com/topic/182074-solved-sorry-for-double-posting-php-live-search-code-question/#findComment-960560 Share on other sites More sharing options...
gene99 Posted November 19, 2009 Author Share Posted November 19, 2009 I am able to take an rss/xml file from all listings in my directory(s) & convert it to a file like this one in 5-10 minutes > http://www.w3schools.com/php/links.xml This is the example file in the php live search code at > http://www.w3schools.com/ . I've done maybe 6-7 different possible changes & none works. I am just looking for a way to allow the <descriptions> in the xml to be keyword searched & the listing title (& url) & description to show in live search dropdown. At present only the title & url are searched. I use friendly urls so it's the same search result always. I can edit out the <title></title> from the xml & switch the <description></description> tags to <title></title> w/ "replace" feature in Notepad but it's a pain. Any help would be really appreciated. Thanks, Gene Quote Link to comment https://forums.phpfreaks.com/topic/182074-solved-sorry-for-double-posting-php-live-search-code-question/#findComment-961417 Share on other sites More sharing options...
MadTechie Posted November 19, 2009 Share Posted November 19, 2009 OKay i assume the XML looks like this <pages> <link> <title>PHP Freaks - This is a sample</title> <description>I am a description</description> <url>http://www.phpfreaks.com/forums/index.php/topic,277452.0/topicseen.html</url> </link> <link> <title>PHP Freaks Main Page</title> <description>PHP Freaks is a website dedicated to learning and teaching PHP. Here you will find a forum consisting of 86915 members who have posted a total of 963580 </description> <url>http://www.phpfreaks.com/forums</url> </link> </pages> from that this should work fine <?php /** $q='description'; // returns 1 $q='Freaks'; // returns 2 */ $xmlDoc = new DOMDocument(); $xmlDoc->load('c:\277452.xml'); $x=$xmlDoc->getElementsByTagName('link'); //get the q parameter from URL $q=$_GET["q"]; //lookup all links from the xml file if length of q>0 if (strlen($q) > 0){ $hint=""; for($i=0; $i<($x->length); $i++){ $a=$x->item($i)->getElementsByTagName('title'); $b=$x->item($i)->getElementsByTagName('description'); $c=$x->item($i)->getElementsByTagName('url'); if ($a->item(0)->nodeType==1){ //find a link matching the search text if (stristr($a->item(0)->childNodes->item(0)->nodeValue,$q) || stristr($b->item(0)->childNodes->item(0)->nodeValue,$q)){ $hint .= "<a href='" . $c->item(0)->childNodes->item(0)->nodeValue . "' target='_blank'>" . $a->item(0)->childNodes->item(0)->nodeValue . "</a>". $b->item(0)->childNodes->item(0)->nodeValue . "<br />\n"; } } } } // Set output to "no suggestion" if no hint were found // or to the correct values if ($hint == "") { $response="no suggestion"; }else{ $response=$hint; } //output the response echo $response; ?> Quote Link to comment https://forums.phpfreaks.com/topic/182074-solved-sorry-for-double-posting-php-live-search-code-question/#findComment-961449 Share on other sites More sharing options...
gene99 Posted November 20, 2009 Author Share Posted November 20, 2009 It works great! Thank you so much. Do you mind if I post this solution at PhpMyDirectory boards? If you ever need any help over there let me know. Maybe I can help ya. I'll see how well we can tackle the css to get a better look maybe & post it back here. Thanks again, gene99 Quote Link to comment https://forums.phpfreaks.com/topic/182074-solved-sorry-for-double-posting-php-live-search-code-question/#findComment-961553 Share on other sites More sharing options...
MadTechie Posted November 20, 2009 Share Posted November 20, 2009 I don't mind, of course I couldn't exactly stop you either It may be worth including a link back to here (if its allowed), but I'll leave it up to you Quote Link to comment https://forums.phpfreaks.com/topic/182074-solved-sorry-for-double-posting-php-live-search-code-question/#findComment-961557 Share on other sites More sharing options...
gene99 Posted November 20, 2009 Author Share Posted November 20, 2009 Consider it done. Thanks alot, Gene Quote Link to comment https://forums.phpfreaks.com/topic/182074-solved-sorry-for-double-posting-php-live-search-code-question/#findComment-961572 Share on other sites More sharing options...
MadTechie Posted November 20, 2009 Share Posted November 20, 2009 Your very welcome Quote Link to comment https://forums.phpfreaks.com/topic/182074-solved-sorry-for-double-posting-php-live-search-code-question/#findComment-961586 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.