Jump to content

Seriously stumped with paging and allowed pages


solvision

Recommended Posts

Hey Guys

 

OK i've just launched the 3rd version of my companies website. Inside the admin section are pages calling mysql results. I am using the following code for my pages:

 

<?php

// which page should be shown now

$page = (isset($_GET['page']) && $_GET['page'] != '') ? $_GET['page'] : 'horizon-recruitment-esl-home';

 

// only the pages listed here can be accessed

// any other pages will result in error

$allowedPages = array('pages are in here, and plenty of them');

 

if (!in_array($page, $allowedPages)) {

  $page = 'notfound';

}

 

// Call header file which contains all meta tags, keywords, etc

include ('header.php');

  include $page. '.php';

  ?>

 

OK, now the trouble is, when i use any pagination script such as this:

 

if ($pageno == $lastpage) {

  echo " NEXT LAST ";

} else {

  $nextpage = $pageno+1;

  echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage'>NEXT</a> ";

  echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$lastpage'>LAST</a> ";

} // if

 

I cannot get past the first page. I have found that:( $_SERVER['PHP_SELF'] doesn't keep the included page path. For example:

 

The user is at index.php?page=directory1/directory2/page1

 

Page1 has pagination, and is correctly only showing the first 20 results. When you click on the page 2 link, i am expecting this:

index.php?page=directory1/directory2/page1&pageno=2

 

But what I get is: index.php?pageno=2

 

So i'm losing the entire path (page=directory1/directory2/page1).

 

So 1) How do i keep that whole path?, and;

 

now the second part of the question...Because I am already using "?" on the index page structure, do I now need to use "&" in the pagination script. I have tried using it (i swapped the php_self call for the full path), but i get a page not included error for anything past the first page.

 

So, can anyone help me fix this? In the second version of the site i had a lot of duplicate code and pages to get the pagination working. I have learnt a fair bit more about how it works since then, and in the most recent version, i have about half as many pages/code.

 

I am trying to keep from duplicating code as much as possible, the idea was to keep this version clean and tidy.

 

Can anyone help me solve this, and perhaps explain the reason why the above problem is happening/alternative method for pagination?

 

Thanks in advance.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.