Need help editing this script

gooooogle

New member
Hi I need help editing a search engine script I found which I am now trying to customize to my needs.

Here is the code.
<!-- You can INSERT a header here -->
<?



if($_POST['action'] == "search") {

include "config.php";
$filename = "$root/site.dat";

if(strlen($_POST['keyword']) <= 1){
print "<p><b>Your keyword must be longer than 1 characters</b><br>";
}
else{

$keyword = $_POST['keyword'];

function getmicrotime(){
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}


$user = file("$filename");
$searching = count($user);
$lis = 0;
for($x=0;$x<sizeof($user);$x++) { // start loop, each line of file
$temp = explode("|",$user[$x]); // explode the line and assign to temp
$line[$x] = "$temp[0]|$temp[1]|$temp[2]|$temp[3]"; // create array of temp

$keyword = trim($keyword, " ");
$keywords = explode(" ", $keyword);

$matchexact = true; // testing

if($matchexact){
foreach ($keywords as $word){
if(preg_match ("/\b$word\b/i", $temp[3]) || preg_match ("/\b$word\b/i", $temp[0])) { // added 27/05/03
$collect[$lis] = $line[$x];
$lis++;
}
}
}
else{
foreach ($keywords as $word){
if(preg_match ("/$word/i", $temp[3]) || preg_match ("/$word/i", $temp[0])) { // added 27/05/03
$collect[$lis] = $line[$x];
$lis++;
}
}
}

}

$time = microtime();
$time = number_format($time,3);

if($lis > 0){
$list = array_values(array_unique($collect));
}
else $list = $collect;
//var_dump($list);


if(sizeof($list) != "0") {

//sort($keyword);
echo "<p><b>",sizeof($list),"</b> Search Result(s) Found For <b>$keyword</b></p></font>";

for($y=0;$y<sizeof($list);$y++) {
$temp = explode("|",$list[$y]);
echo '<li><a href=',$temp[2],'><b>',$temp[0],'</a></b><br>',$temp[1],'<BR><font color=gray><small>',$temp[2],'</small></font><BR><BR>';
}
if($stats == true){
echo "<p>Searching <b>$searching</b> pages | Search executed in <b>$time</b> seconds.<br><br>";
}
}

else{
echo "<p>Sorry but we could not find any results for <b>$keyword.</b><br><br>";
if($stats == true){
echo "Search executed in <b>$time</b> seconds.<br>";
}
}

?>
<form action="<? echo ($_SERVER['PHP_SELF']); ?>" method="post">
Search Again:
<input type="text" name="keyword" size="20" maxlength="100">
<input type="submit" name="submit" value="Search">
<input type ="hidden" name="action" value ="search">
</form>

<?


}
}
else if(!$action || $action == ""){
?>
<form action="<? echo ($_SERVER['PHP_SELF']); ?>" method="post">
Search:
<input type="text" name="keyword" size="20" maxlength="100">
<input type="submit" name="submit" value="Search">
<input type ="hidden" name="action" value ="search">
</form>
<?
}

// Please keep the copyright below intact so others can benefit from this script!
// If you would like to donate please visit http://www.cj-design.com/?id=donate
?>

<p><center><small>© 2004 by vision-park.net. All Rights Reserved<br>CJ Website Search V1.0 © <A HREF="http://www.cj-design.com">CJ Website Design</A></small></center>


<!-- You can INSERT a footer here -->


This is what it looks like

Try searching for google and you'll see how it works.

What I want to do is make it so that the search box is always at the top, also while listing search results. What do I need to do to the code?
 
There are 2 ways you can do this. You can make the search form its own seperate php page and use the 'include' function to have it load where you want. Or you can simply re-arrage the code.

If you were to rearange the code. This segment of code:

<form action="<? echo ($_SERVER['PHP_SELF']); ?>" method="post">
Search:
<input type="text" name="keyword" size="20" maxlength="100">
<input type="submit" name="submit" value="Search">
<input type ="hidden" name="action" value ="search">
</form>

needs to be posted prior to:
if(sizeof($list) != "0") {

I think this should do it... not sure. I would have to play around with it a bit.
 
Back
Top