Pagination PHP, htaccess

Go To StackoverFlow.com

1

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!!!

2012-04-05 16:28
by Veni
I am confused. Would you rewrite the question, so its a bit easy to grasp the concept, rather than go of and on - Starx 2012-04-09 12:30
Sorry about the not structuring my question well. If you need any more details, I will provide. Thank you for trying to help me - Veni 2012-04-09 12:43
@Starx - his question is pretty easy to understand, I wouldn't say he go's on and on... how else should he have written it - Flukey 2012-04-09 13:27


3

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]
2012-04-09 13:03
by Tom Imrei
Thanks, that resolved the relativeness issue but I still get to stay on the same page even if I press the page numbers. Actually, $mpage is the parameter I use for pagination, and $page is the parameter for my site's main pages- home, materials, etc. So I wonder is this something with htaccess blocking navigation - Veni 2012-04-09 13:14
It's hard to say anything more specific without the full code - Tom Imrei 2012-04-09 13:18
I could send the whole code. Would you have a look at it if I do? Thank you for your help - Veni 2012-04-09 13:29
paste it at pastebin.com and add the link her - Tom Imrei 2012-04-09 13:31
More on issue: If I have e.g. localhost/en/materials?mpage=2 and I press Next button, the value of $mpage changes in the URL localhost/en/materials?mpage=3. If I press any page number, the value of $mpage changes accordingly, but in fact it always stays on page 1. Only the URL changes - Veni 2012-04-09 14:59
THANK YOU SO MUCH!!! :- - Veni 2012-04-10 06:45
Ads