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

Asked

Viewed 329 times

3

I am making a site and on this site, I have a simple pagination site 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 is in this page above and inside it (page studies), I have a pagination system that passes more parameters $_Get, as Id, to generate the Count pagination equal to this:

 usando  o get ela passa um id <code>?pag=1<b</code>

Someone knows the way to pass INDEX?PAG=ESTUDOS and within study the pagination id? I think it’s something more or less like this index?pag=estudos&1 I just don’t know how to do it.

  • 2

    Usually a pagination is fed by DB content - what you’re doing is manual is_file( 'Paginas/'.$pg.'.php' ), you have the files pg1.php, pg2.php, ... pg100.php physically?

3 answers

8


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

inserir a descrição da imagem aqui

$_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'];
  • 3

    People, vote on this answer more!

4

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

index.php?secao=estudos&pagina=1

(Adjust parameter names as needed.)

  • Do you mean passing a Session_start ? http://php.net/manual/en/function.session-start.php

  • Session_start? I’m showing you how to pass more than one parameter for GET: "studies" and the page number. Maybe you misunderstood the question correctly.

  • 3

    what is bfavaretto indicated, is a link that will pass the n. of the page and you just need to use $_GET['pagina'] to retrieve it.

  • Vlw Friend now worked out !!! It had not worked out because I had put a same $_GET for section and vlw page

  • Don’t forget to mark as solved

  • 3

    When choosing what to mark as solved, consider Jader’s response, which is more detailed.

Show 1 more comment

1

is as Jader said above, key=value:

index.php?secao=estudos&pagina=1

And in your controller (or something like that) 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 dry

$secao = $_GET['secao'];
$secao = ($secao == '') ? 'sua_secao_default' : $secao;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.