Veni
Veni

Reputation: 127

Pagination PHP, htaccess

I initialize $page the following way: $mpage = trim( ( isset( $_GET[ 'mpage' ] ) ? $_GET[ 'mpage' ] : '1' ), '/' );

For page materials the $_SERVER['REQUEST_URI']) is http://localhost/en/materials I would like to implement paging of the materials available, e.g. localhost/en/materials?mpage=3 or localhost/en/materials?mpage=2.

Is this something to do with htcaccess? Please help me out. Thanks!!!

Upvotes: 1

Views: 932

Answers (1)

Tom Imrei
Tom Imrei

Reputation: 1544

Use $_SERVER["SCRIPT_URI"] instead of $_SERVER["REQUEST_URI"]:

...
$mpage = $_GET['mpage'];
...
$currpage = $_SERVER["SCRIPT_URI"];
...

EDIT & EDIT 2: fixed $mpage variable name

UPDATE

The problem is in the rewrite, you need to add the QSA flag to all redirects to "keep" the mpage parameter as well:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f                [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .  -                                  [L]

RewriteRule ^$ index.php                          [QSA,L]
RewriteRule ^admin/?$ admin/index.php             [QSA,L]
RewriteRule ^admin/(.*)$ admin/index.php?page=$1  [QSA,L]
RewriteRule ^(.*)/(.*)$ index.php?lang=$1&page=$2 [QSA,L]
RewriteRule ^(.*)$ index.php?lang=en&page=$1      [QSA,L]

Upvotes: 3

Related Questions