문제

I made a simple table class with pager for my project in php. It works fine if the page address does not contain any params passed by GET method. Here is the way Im creating the table with pager

$tbl = new table();
$tbl->headers(array ("Header1", "Header2"));
$query = "SELECT COUNT(*) FROM table";
$tbl->pager(15, $query);           
$tbl->page = $_SERVER['PHP_SELF'];
$query = "SELECT id, name, FROM table";
$tbl->createTable($query);

I want to use it in the switch function

switch ($_GET['a']) {
        case b:
            $tbl = new table();
            $tbl->headers(array ("Header1", "Header2"));
            $query = "SELECT COUNT(*) FROM table";
            $tbl->pager(15, $query);

            $tbl->page = $_SERVER['REQUEST_URI'];
            $query = "SELECT id, name, FROM table";
            $tbl->createTable($query);
            break;
        case c:
            ...
            break;
    }

and $_SERVER['REQUEST_URI'] will pass page.php?a=b to the pager and create pager as it should be. Problem occurs when I switch between pages because REQUEST_URI each time pass page.php?a=b + actual page number I am on to the pager so the address looks like pager.php?a=b&page1&page=2.... And my question is, is there a way to pass to pager only page.php?a=b and make it to be nonchangeable or sth like that ?? Hope my question is clear.

도움이 되었습니까?

해결책

sd

function getQE(){
     if($_GET){ 
       // exlude some variables from $_GET (pass names of variables in function call)
       $ex = func_get_args();
       $qstr  = "?";
       foreach($_GET as $key=>$value) {
          if (!in_array($key, $ex)){
              $qstr .= $key."=".$value;
              $qstr .= '&';
          }
       }
     }
return $qstr;
}

in your case to get query string without 'page' you should call this function like this:

$get = getQE('page');

if you need to exclude more than one:

$get = getQE('page', 'section','folder');
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top