Page 1 of 1

php?=page with php?=page

Posted: Tue Aug 31, 2004 5:28 am
by buddok
ok well this si realy hard to explain :

i have index2.php

which includes a file for example

index2.php?page=home

which would include home.php into the main text area.

in home.php i am including

links.php (this page has my page numbering in)

the page numbering links go like so:

<a href='$PHP_SELF?page= (then the number of the page)

but because this is on index2.php?page=home

it jus changes it to

index2.php?page=1 or 2 or wat ever

when i need it to be somthing like this

index2.php?page=home&page=1

does anyone no what im doin wrong could someone tell me how to link these properly ? :( ?

Posted: Tue Aug 31, 2004 7:27 am
by timvw
Offcourse, you might want to add url encoding etc...

But here is a basic example:

Code: Select all

<?php

// use my improved version of $_SERVER['PHP_SELF'];
require_once('http://home.mysth.be/~timvw/programming/php/geturl.txt');
$url = geturl();

$args = array('arg2' => 'val2', 'arg3' => 'val3');

echo buildurl($url, $args);

function buildurl($url, $args)
{
  // test if there are already $_GET variables
  $has_get = false;

  $pos = strpos($url, '?');
  if ($pos === false)
  {
    $has_get = false;
  }
  else
  {
    $has_get = true;
  }

  // now add each pair to the url
  foreach($args as $key => $val)
  {
    if ($has_get)
    {
      $url .= '&' . $key . '=' . $val;
    }
    else
    {
      $url .= '?' . $key . '=' . $val;
    }
    $has_get = true;
  }

  return $url;
}
?>

Posted: Tue Aug 31, 2004 9:30 am
by d3ad1ysp0rk
index.php?page=home&pagenum=1