php?=page with php?=page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
buddok
Forum Commoner
Posts: 50
Joined: Tue May 25, 2004 2:44 pm

php?=page with php?=page

Post 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 ? :( ?
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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;
}
?>
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

index.php?page=home&pagenum=1
Post Reply