所以我有index.php
,function.php
,index.tpl
和show_results.tpl
。
在index.php
我有以下内容:
<?php
include('setari_assign.php');
include('functii/functii.php');
$smarty->display('index.tpl');
if($_SERVER['REQUEST_METHOD'] == 'POST'){
search($a1,$a2,$a3,$a4,a5,$a6,$a7['string']);
$smarty->display('afisare_rez.tpl'); }
?>
在function.php
中,分页看起来像:
<?php
function paginare($items,$per_page = 10, $page = 1, $url = '?')
{
$total = count($items);
$adjacent = "2";
$page = ($page == 0 ? 1 : $page);
$start = ($page - 1 ) * $per_page;
$prev = $page - 1;
$next = $page + 1;
$lastPage = ceil($total/$per_page);
$lpm1 = $lastPage;
$pagination = "";
if($lastPage > 1)
{
$pagination .= "<ul class='pagination'>";
$pagination .= "<li class='detalis'>Page $page from $lastPage</li>";
if($lastPage < 7 + ( $adjacent * 2))
{
for ($counter = 1; $counter <= $lastPage; $counter++)
{
if($counter == $page)
$pagination .="<li><a class='current'>$counter</a></li>";
else
$pagination.="<li><a href='{$url}page=$counter'>$counter</a></li>";
}
}
elseif($lastPage > 5 + ($adjacents * 2))
{
if($page < 1 + ($adjacent * 2))
{
for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
{
if($counter == $page)
$pagination.="<li><a class='current'>$counter</a></li>";
else
$pagination.="<li><a href='{$url}page=$counter'>$counter</a></li>";
}
$pagination.="<li><a href='dot'>....</li>";
$pagination.="<li><a href='{$url}page=$lpm1'>$lpm1</a></li>";
$pagination.="<li><a href='{$url}page=$lastPage'>$lastPage</a></li>";
}
elseif($lastPage - ($adjacent * 2) > $page && $page > ( $adjacent * 2))
{
$pagination.="<li><a href='{$url}page=1'>1</a></li>";
$pagination.="<li><a href='{$url}page=2'>2</a></li>";
$pagination.="<li class='dot'>....</li>";
for($counter = $page - $adjacent; $counter <= $page + $adjacent; $counter++)
{
if($counter == $page)
$pagination.="<li><a class='current'>$counter</a></li>";
else
$pagination.="<li><a href='{$url}page=$counter'>$counter</a></li>";
}
$pagination.="<li class='dot'>....</li>";
$pagination.="<li><a href='{$url}page=$lpm1'>$lpm1</a><li>";
$pagination.="<li><a href='{$url}page=$lastPage'>$lastPage</a></li>";
}
else
{
$pagination.= "<li><a href='{$url}page=1'>1</a></li>";
$pagination.= "<li><a href='{$url}page=2'>2</a></li>";
$pagination.="<li class='dot'>....</li>";
for($counter = $lastPage - (2 + ($adjacent * 2)); $counter <= $lastPage; $counter++)
{
if($counter == $page)
$pagination.="<li><a class='current'>$counter</a></li>";
else
$pagination.="<li><a href='{$url}page=$counter'>$counter</a></li>";
}
}
}
if($page < $counter - 1)
{
$pagination.="<li><a href='{$url}page=$next'>NEXT</a></li>";
$pagination.="<li><a href ='{$url}page=$lastPage'>LAST</a></li>"; } else {
$pagination.="<li><a class='current'>NEXT</a></li>";
$pagination.="<li><a class='current'>LAST</a></li>";
}
$pagination.="</ul>\n";
}
return $pagination;
}
?>
...而show_results.tpl
是:
<div class="records round" align="left">
<div class="record round">
<p>Results:</p>
<?php
$page = (int) (!isset($_GET["page"]) ? 1 : $_GET["page"]);
$limit = 5;
$startpoint = ($page * $limit) - $limit;
foreach($results as $i => $value)
{
echo '<div class="record round">';
echo($results[$i]['title']) ;
echo "<br /><br />";
echo($results[$i]['content']);
echo "<br /><br />";
echo('<a href="'.$results[$i]['url'].'" target="_blank">'.$results[$i]['url'].'</a>');
</div>
}
}
?>
</div>
}
echo pagination($results,$limit,$page);
?>
</div></div>
在第一次运行时,脚本完美运行,显示索引。搜索结果后,结果会以分页显示,但当我尝试转到第2页的分页时,它会转到原始index.tpl
。
我做错了什么?