How to pass Id next to pagination ex: index? pag = page & ID?

3

I am making a website and in this site, I have a simple paging system in index.php with the following code:

<?php
    function getGet( $key ){
            return isset( $_GET[ $key ] ) ? $_GET[ $key ] : null;
    }
            $pg = getGet('pag');
            if( is_file( 'Paginas/'.$pg.'.php' ) )
                    include 'Paginas/'.$pg.'.php'; 
            else
                    include 'Paginas/home.php';

I have a page called studies that stays in this pagination above and inside it (page studies), I have a paging system that passes more parameters $_Get , like Id, to generate pagination by Count equal to this:

Does anyone know how to pass INDEX?PAG=ESTUDOS and within study the paging id? I think it's something like this index?pag=estudos&1 but I do not know how to do it.

    
asked by anonymous 14.08.2014 / 21:56

3 answers

8

All variables passed in the URL after the sign of ? (separated by & ) can be obtained in PHP using the array superglobal $ _GET as in the diagram below: / p>

$_GET['pag'] == 'estudos'
$_GET['pagina'] == 1
$_GET['tipo'] == 'avançado'

That is, your line:

$pg = getGet('pag');

is almost the same as:

$pg = $_GET['pag'];
    
14.08.2014 / 22:26
4

Parameters passed by GET must be in chave=valor format. So you can do something like this:

index.php?secao=estudos&pagina=1

(Adjust the parameter names as needed.)

    
14.08.2014 / 21:59
1

It's how Jader said above, key = value:

index.php?secao=estudos&pagina=1

And in your controller (or something similar) to know which page you should send you do the following:

/*
aqui resgatamos o valor, caso ele não exista ou não seja um inteiro o valor
atribuido a $pagina ser 0 (zero) 
*/
$pagina = (int) $_GET['pagina'];

/*
se o valor for 0 mudamos para um porque imagino que você não tenha a página 0
*/
$pagina = ($pagina == 0) ? 1 : $pagina;

Now the same with drying

$secao = $_GET['secao'];
$secao = ($secao == '') ? 'sua_secao_default' : $secao;
    
15.08.2014 / 19:22