Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't seem to load the correct page with Smarty and pagination
    text
    copied!<p>So I have an <code>index.php</code>, <code>function.php</code>, <code>index.tpl</code>, and <code>show_results.tpl</code>.</p> <p>In <code>index.php</code> I have the following:</p> <pre><code>&lt;?php include('setari_assign.php'); include('functii/functii.php'); $smarty-&gt;display('index.tpl'); if($_SERVER['REQUEST_METHOD'] == 'POST'){ search($a1,$a2,$a3,$a4,a5,$a6,$a7['string']); $smarty-&gt;display('afisare_rez.tpl'); } ?&gt; </code></pre> <p>In <code>function.php</code> the pagination looks like:</p> <pre><code>&lt;?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 &gt; 1) { $pagination .= "&lt;ul class='pagination'&gt;"; $pagination .= "&lt;li class='detalis'&gt;Page $page from $lastPage&lt;/li&gt;"; if($lastPage &lt; 7 + ( $adjacent * 2)) { for ($counter = 1; $counter &lt;= $lastPage; $counter++) { if($counter == $page) $pagination .="&lt;li&gt;&lt;a class='current'&gt;$counter&lt;/a&gt;&lt;/li&gt;"; else $pagination.="&lt;li&gt;&lt;a href='{$url}page=$counter'&gt;$counter&lt;/a&gt;&lt;/li&gt;"; } } elseif($lastPage &gt; 5 + ($adjacents * 2)) { if($page &lt; 1 + ($adjacent * 2)) { for ($counter = 1; $counter &lt; 4 + ($adjacents * 2); $counter++) { if($counter == $page) $pagination.="&lt;li&gt;&lt;a class='current'&gt;$counter&lt;/a&gt;&lt;/li&gt;"; else $pagination.="&lt;li&gt;&lt;a href='{$url}page=$counter'&gt;$counter&lt;/a&gt;&lt;/li&gt;"; } $pagination.="&lt;li&gt;&lt;a href='dot'&gt;....&lt;/li&gt;"; $pagination.="&lt;li&gt;&lt;a href='{$url}page=$lpm1'&gt;$lpm1&lt;/a&gt;&lt;/li&gt;"; $pagination.="&lt;li&gt;&lt;a href='{$url}page=$lastPage'&gt;$lastPage&lt;/a&gt;&lt;/li&gt;"; } elseif($lastPage - ($adjacent * 2) &gt; $page &amp;&amp; $page &gt; ( $adjacent * 2)) { $pagination.="&lt;li&gt;&lt;a href='{$url}page=1'&gt;1&lt;/a&gt;&lt;/li&gt;"; $pagination.="&lt;li&gt;&lt;a href='{$url}page=2'&gt;2&lt;/a&gt;&lt;/li&gt;"; $pagination.="&lt;li class='dot'&gt;....&lt;/li&gt;"; for($counter = $page - $adjacent; $counter &lt;= $page + $adjacent; $counter++) { if($counter == $page) $pagination.="&lt;li&gt;&lt;a class='current'&gt;$counter&lt;/a&gt;&lt;/li&gt;"; else $pagination.="&lt;li&gt;&lt;a href='{$url}page=$counter'&gt;$counter&lt;/a&gt;&lt;/li&gt;"; } $pagination.="&lt;li class='dot'&gt;....&lt;/li&gt;"; $pagination.="&lt;li&gt;&lt;a href='{$url}page=$lpm1'&gt;$lpm1&lt;/a&gt;&lt;li&gt;"; $pagination.="&lt;li&gt;&lt;a href='{$url}page=$lastPage'&gt;$lastPage&lt;/a&gt;&lt;/li&gt;"; } else { $pagination.= "&lt;li&gt;&lt;a href='{$url}page=1'&gt;1&lt;/a&gt;&lt;/li&gt;"; $pagination.= "&lt;li&gt;&lt;a href='{$url}page=2'&gt;2&lt;/a&gt;&lt;/li&gt;"; $pagination.="&lt;li class='dot'&gt;....&lt;/li&gt;"; for($counter = $lastPage - (2 + ($adjacent * 2)); $counter &lt;= $lastPage; $counter++) { if($counter == $page) $pagination.="&lt;li&gt;&lt;a class='current'&gt;$counter&lt;/a&gt;&lt;/li&gt;"; else $pagination.="&lt;li&gt;&lt;a href='{$url}page=$counter'&gt;$counter&lt;/a&gt;&lt;/li&gt;"; } } } if($page &lt; $counter - 1) { $pagination.="&lt;li&gt;&lt;a href='{$url}page=$next'&gt;NEXT&lt;/a&gt;&lt;/li&gt;"; $pagination.="&lt;li&gt;&lt;a href ='{$url}page=$lastPage'&gt;LAST&lt;/a&gt;&lt;/li&gt;"; } else { $pagination.="&lt;li&gt;&lt;a class='current'&gt;NEXT&lt;/a&gt;&lt;/li&gt;"; $pagination.="&lt;li&gt;&lt;a class='current'&gt;LAST&lt;/a&gt;&lt;/li&gt;"; } $pagination.="&lt;/ul&gt;\n"; } return $pagination; } ?&gt; </code></pre> <p>... and <code>show_results.tpl</code> is:</p> <pre><code>&lt;div class="records round" align="left"&gt; &lt;div class="record round"&gt; &lt;p&gt;Results:&lt;/p&gt; &lt;?php $page = (int) (!isset($_GET["page"]) ? 1 : $_GET["page"]); $limit = 5; $startpoint = ($page * $limit) - $limit; foreach($results as $i =&gt; $value) { echo '&lt;div class="record round"&gt;'; echo($results[$i]['title']) ; echo "&lt;br /&gt;&lt;br /&gt;"; echo($results[$i]['content']); echo "&lt;br /&gt;&lt;br /&gt;"; echo('&lt;a href="'.$results[$i]['url'].'" target="_blank"&gt;'.$results[$i]['url'].'&lt;/a&gt;'); &lt;/div&gt; } } ?&gt; &lt;/div&gt; } echo pagination($results,$limit,$page); ?&gt; &lt;/div&gt;&lt;/div&gt; </code></pre> <p>On the first run the script works perfectly, the index is shown. After a search, the results appear with the pagination, but when I try to go to page 2 on the pagination it goes to the original <code>index.tpl</code>.</p> <p>What am I doing wrong?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload