Hi everybody,
I have this search script that indexes my site fine, then when it comes to the results page it only displays the first page of results. Now it creates many pages that has results on like 1 2 3 4 5 6 7 etc… Now eventually I would like to do what google do and have < > either side after 1 – 10 so it wont ruin the layout of the page (but that will be later hopefully) as at the moment it displays 1 – 70 if you search for a major keyword.
If you go to [url]www.sunpipe.co.uk
Can anyone help me please, I will post the rest of the code?
Heres the form that
[code=php]
<?php function __get($key) { return isset($_GET[$key]) ? htmlentities($_GET[$key]) : “”; } ?>
<form method=”get” target=”top” action=”/search/index.php”>
<input class=”text” type=”text” name=”allwords” value=”<?=__get(“allwords”);?>” />
<input class=”submit” onMouseOver=”this.classname=upstate” onMouseOut=”this.classname=hoverstate” type=”submit” value=”Search” />
<input type=”hidden” name=”offset” value=”0″ />
<input type=”hidden” name=”words” value=”<?=__get(“words”);?>” /> <!– At least one of these words –>
<input type=”hidden” name=”nowords” value=”<?=__get(“nowords”);?>” /> <!– None of these words –>
</form>
Heres the display function from the api page:
[code=php]
// —– Display —————————————————————
function display($results, $words, $allwords, $nowords,
$offset, $limit, $numrows, $time,
$template_all, $template_ind, $template_cur, $template_ref, $template_non)
{
if ($numrows == 0)
{
echo $template_non;
return;
}
$ind = “”;
for ($i = 0; $i < (integer)(($numrows+$limit-1)/$limit); $i++)
{
$trans = Array(“%%page%%” => $i+1,
“%%offset%%” => $i*$limit,
“%%words%%” => urlencode($words),
“%%allwords%%” => urlencode($allwords),
“%%nowords%%” => urlencode($nowords));
if ($i*$limit == $offset)
$ind .= strtr($template_cur, $trans);
else $ind .= strtr($template_ind, $trans);
}
$ref = “”;
foreach ($results as $i => $result)
{
$trans = Array(“%%url%%” => $result[“url”],
“%%title%%” => $result[“title”],
“%%excerpt%%” => $result[“excerpt”]);
$ref .= strtr($template_ref, $trans);
}
$trans = Array(“%%ind%%” => $ind,
“%%ref%%” => $ref,
“%%numrows%%” => $numrows,
“%%time%%” => $time);
echo strtr($template_all, $trans);
}
?>
Heres the inc_results page:
[code=php]
<?php
if (isset($_GET[‘words’]))
{
include_once “init.php”;
$offset = isset($_GET[‘offset’ ]) ? (integer)$_GET[‘offset’] : 0;
$words = isset($_GET[‘words’ ]) ? strtolower($_GET[‘words’ ]) : ”;
$allwords = isset($_GET[‘allwords’]) ? strtolower($_GET[‘allwords’]) : ”;
$nowords = isset($_GET[‘nowords’ ]) ? strtolower($_GET[‘nowords’ ]) : ”;
$time = microtime(true);
$result = search(preg_split(“/[^a-z]+/”, $words, -1, PREG_SPLIT_NO_EMPTY),
preg_split(“/[^a-z]+/”, $allwords, -1, PREG_SPLIT_NO_EMPTY),
preg_split(“/[^a-z]+/”, $nowords, -1, PREG_SPLIT_NO_EMPTY),
$offset, $src_results_per_page, $numrows);
$time = microtime(true)-$time;
$time = number_format($time, 2, ‘.’, ”);
$template_all = file_get_contents(“template_all.txt”);
$template_ind = file_get_contents(“template_ind.txt”);
$template_cur = file_get_contents(“template_cur.txt”);
$template_ref = file_get_contents(“template_ref.txt”);
$template_non = file_get_contents(“template_non.txt”);
display($result, $words, $allwords, $nowords,
$offset, $src_results_per_page, $numrows, $time,
$template_all, $template_ind, $template_cur, $template_ref, $template_non);
}
?>