Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > SEARCH SCRIPT HELP!

Reply
Thread Tools

SEARCH SCRIPT HELP!

 
 
Benji
Guest
Posts: n/a
 
      07-31-2007
I recently found this search engine script while searching the net
recently and desperately need help with it. The script displays search
hippo results via xml feed and the sponsored results on the right hand
side are from revenue pilot. The script works except there is a bug.
The first query works fine (it displays 10 results per page) however
when you click "next" to go to the next page it will display 15 and
next page it will display 20 then 25 and so on. The other problem is
that the table size of the search hippo results on the odd occasion
will get bigger and will throw the revenue pilot results on the right
hand side out of view. I imagine that someone with knowledge of these
things would be able to rectify it quite easily, however this is a bit
above my head. If somebody could help me with this it will be very
much appreciated.

Here is the search results file (search.php)


<p><?php

// (C) 2003 C P Ridings
// Create a search engine the easy way using searchhippo and
revenuepilot

// Change the layout by editing the index.html page and the template
results.tpl

// This is a revenuepilot affiliate id for the paying side ads.
// If you want to use your own id here you MUST get it from
http://www.revenuepilot.com/iebar/ ONLY

$revid=1833;

// Class to hold the SearchHippo results
class shItem {
var $shTitle;
var $shDescription;
var $shURL;
var $shDispURL;
}

// Class to hold the RevenuePilot Ads
class rpAds {
var $rpTitle;
var $rpLink;
var $rpDomain;
var $rpDescription;
}

$sTitle = "";
$sLink = "";
$sDescription = "";
$arItems = array();
$itemCount = 0;
$resultscount=0;
$nexturl="";
$prevurl="";
$theirip=$_SERVER['REMOTE_ADDR'];
$adsItems = array();
$adscount = 0;
$curTag="";

function startElement($parser, $name, $attrs) {
global $curTag, $prevurl, $nexturl;
$curTag .= "^$name";
if ($name == "RESULTS") {
// Get the results count and previous and next urls
$resultscount=trim($attrs["COUNT"]);
$nexturl=trim($attrs["NEXTURL"]);
$prevurl=trim($attrs["PREVURL"]);
}
}

function endElement($parser, $name) {
global $curTag;
$caret_pos = strrpos($curTag,'^');
$curTag = substr($curTag,0,$caret_pos);
}


function characterData($parser, $data) {
global $curTag;

// now get the items
global $arItems, $itemCount;
$itemTitleKey = "^SEARCHHIPPO^RESULTS^RECORD^TITLE";
$itemLinkKey = "^SEARCHHIPPO^RESULTS^RECORD^URL";
$itemDispKey = "^SEARCHHIPPO^RESULTS^RECORD^DISPURL";
$itemDescKey = "^SEARCHHIPPO^RESULTS^RECORD^DESCR";
if ($curTag == $itemTitleKey) {
// make new xItem
$arItems[$itemCount] = new shItem();
// set new item object's properties
$arItems[$itemCount]->shTitle = $data;
}
elseif ($curTag == $itemLinkKey) {
$arItems[$itemCount]->shURL = $data;
}
elseif ($curTag == $itemDescKey) {
$arItems[$itemCount]->shDescription = $data;
}
elseif ($curTag == $itemDispKey) {
$arItems[$itemCount]->shDispURL = $data;
$itemCount++;
}
}

function rpstartElement($parser, $name, $attrs) {
global $curTag, $adsItems, $adscount;
$curTag .= "^$name";
if ($name == "LISTING") {
$adsItems[$adscount] = new rpAds();
$adsItems[$adscount]->rpTitle = trim($attrs["TITLE"]);
$adsItems[$adscount]->rpLink = trim($attrs["LINK"]);
$adsItems[$adscount]->rpDomain = trim($attrs["DOMAIN"]);
$adsItems[$adscount]->rpDescription = trim($attrs["DESCRIPTION"]);
$adscount++;
}
}

function rpendElement($parser, $name) {
global $curTag;
$caret_pos = strrpos($curTag,'^');
$curTag = substr($curTag,0,$caret_pos);
}


function rpcharacterData($parser, $data) {
}

if ($HTTP_GET_VARS) {
$q=$HTTP_GET_VARS['q'];
} else {
$q="";
}

if ($HTTP_GET_VARS) {
$c=$HTTP_GET_VARS['c'];
} else {
$c=0;
}

if ($HTTP_GET_VARS) {
$ir=$HTTP_GET_VARS['i'];
} else {
$ir=0;
}

if ($q == "") {
echo "This is the front page which hasn't been done yet!";
} else {
// Get the SearchHippo XML document
$docurl = "http://www.searchhippo.com/qxml.php?q=" .
urlencode($q) . "&c=" . $c . "&i=" . $ir;
$handle = fopen ($docurl, "r");
$data = "";
while (!feof($handle)) {
$data .= fread($handle, 4096);
}
// Fire up the XML parser
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement",
"endElement");
xml_set_character_data_handler($xml_parser, "characterData");
xml_parse($xml_parser, $data);
xml_parser_free($xml_parser);
$results="";
for ($il = 0; $il < $itemCount; $il++) {
$results.= "<font face=\"Verdana\" size=\"2\">";
$results.= "<a href=\"" . $arItems[$il]->shURL .
"\">";
$results.= $arItems[$il]->shTitle;
$results.= "</a><br>\n";
$results.= $arItems[$il]->shDescription . "<br>";
$results.= "</font><font face=\"Verdana\" size=\"1\" color=
\"#6ec46b\">";
$results.= $arItems[$il]->shDispURL . "</
font><br><br>";
}
fclose ($handle);
// Get RevenuePilot Links
$docurl = "http://search.revenuepilot.com/servlet/search?
mode=xml&id=" . $revid . "&filter=off&perpage=4&ip=" . $theirip .
"&skip=0&keyword=" . urlencode($q);
$handle = fopen ($docurl, "r");
$data = "";
while (!feof($handle)) {
$data .= fread($handle, 4096);
}
$rpxml_parser = xml_parser_create();
xml_set_element_handler($rpxml_parser, "rpstartElement",
"rpendElement");
xml_set_character_data_handler($rpxml_parser, "rpcharacterData");
xml_parse($rpxml_parser, $data);
xml_parser_free($rpxml_parser);
$ads = "";
for ($il = 0; $il < $adscount; $il++) {
$ads.= "<table border=\"0\" bordercolor=\"#FFFFFF\"
cellpadding=\"5\" width=\"170\" bgcolor=\"#FFFFFF\"><tr><a href=\"" .
$adsItems[$il]->rpLink . "\"><td valign=\"top\" onClick=
\"self.location='" . $adsItems[$il]->rpLink . "'\" style=
\"cursor:hand; cursorointer\">";
$ads.= "<font face=\"Verdana\" size=\"2\">";
$ads.= "<a href=\"" . $adsItems[$il]->rpLink . "\">";
$ads.= $adsItems[$il]->rpTitle;
$ads.= "</a><br>\n";
$ads.= $adsItems[$il]->rpDescription . "<br>";
$ads.= "</font><font face=\"Verdana\" size=\"2\" color=
\"#7ec47b\">" . $adsItems[$il]->rpDomain . "\n";
$ads.= "</td></a></tr></table><br>";
}
fclose ($handle);
$handle = fopen ("./results.tpl", "r");
$data = fread ($handle, 1000000);
$data = str_replace("[ADS]", $ads, $data);
$data = str_replace("[RESULTS]", $results, $data);
$data = str_replace("[QUERY]", $q, $data);
$prevl = "";
$nextl = "";
if ($prevurl != "") {
$rc=$c-10;
$rir=$ir-10;
$prevl = "<a href=\"?q=" . urlencode($q) . "&c=" . $rc . "&i=" .
$rir . "\"><font face=\"Verdana\" size=\"2\">Previous</font></a>";
}
if ($nexturl != "") {
$rc=$c+10;
$rir=$ir+10;
$nextl = "<a href=\"?q=" . urlencode($q) . "&c=" . $rc . "&i=" .
$rir . "\"><font face=\"Verdana\" size=\"2\">Next</font></a>";
}
$data = str_replace("[NEXT]", $nextl, $data);
$data = str_replace("[PREV]", $prevl, $data);
echo $data;
}

?>
</p>


HERE IS THE TEMPLATE FILE (results.tpl)



<html>
<head>
<title>[QUERY] :: Results</title>
</head>

<body>

<p><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<p>

<center><font face="Verdana" size="20" color="#0066cc">Easy Search</
font></center><br>
<center><form action="search.php" method="get"><input type="text"
name="q" value="[QUERY]">&nbsp;<input type="hidden" name="c"
value="0"><input type="hidden" name="i" value="0"><input type="submit"
value="Search"></form></center>
<center><a href="http://www.searchguild.com/"><font face="Verdana"
size="2">Brought to you by SearchGuild.com</font></a></center>
<table width="100%" bgcolor="#0062c4">

<tr>
<td><font face="Verdana" size="2" color="#eeeeee">Searched For:
[QUERY]</font></td>
</tr>
</table>
<br>
<table width="100%">
<tr>
<td valign="top">[RESULTS]</td>
<td width="170" valign="top">[ADS]</td>
</tr>
</table>
<center>[PREV]&nbsp;&nbsp;[NEXT]</center>
<br>
<table width="100%" bgcolor="#0062c4">

<tr>
<td><font face="Verdana" color="#eeeeee" size="1">&copy;2003 <a
href="http://www.searchguild.com/">SearchGuild.com</
a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;Powered
by SearchHippo</font></td>
</tr>
</table>
</body>
</html>

please email me on http://www.velocityreviews.com/forums/(E-Mail Removed) thanks

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to execute a script from another script and other script does notdo busy wait. Rajat Python 3 01-08-2010 02:05 PM
RE: How to execute a script from another script and other script doesnotdo busy wait. VYAS ASHISH M-NTB837 Python 2 01-07-2010 08:18 PM
Search Bar not displaying search Engines Zimran Douglas Firefox 1 01-07-2005 02:30 PM
search within a search within a search - looking for better way...my script times out Abby Lee ASP General 5 08-02-2004 04:01 PM



Advertisments