Jump to content

[SOLVED] dynamic link help!


crazy/man

Recommended Posts

Hi all,

 

i dont't know how to explain this to you well but i have some problem as i am making new web site.

 

i have links on my page that look like this: 

index.php?site=coverage

 

so i click on that link and it includes new php site inside index.php and in navigationbar in your browser you can see this:

http://mydomain.com/index.php?site=coverage

 

but now i want to open one more site so new link should look like this: 

&video=video2

 

so how can i do that...so it automatically adds new link on existing navigation bar... so it looks like this:

 

http://mydomain.com/index.php?site=coverage&video=video2

 

but it loads me this: 

http://mydomain.com/&video=video2

and ofc it isn't working

Link to comment
Share on other sites

thats the code i am trying to use but it still isnt working

 

<a href="<?php echo $_SERVER['PHP_SELF'] ?>?&coverage=balanesports2">

 

 

well it does load page correctly but it loads it like this:

 

http://mydomain.com/index.php?&coverage=balanesports2

 

and i need it to loead like this:

http://mydomain.com/index.php?site=news&coverage=balanesports2

 

i just need newlink to be added on the old ones that are already loaded

Link to comment
Share on other sites

I added you but let me explain this

 

//Base reference, the page you are on now
$Path = "index.php?";

//Loop through all the $_GET value in your URL already
foreach($_GET as $k => $v)
   {
   //Add them to path again
   $Path .= $k . "=" . $v . "&";
   }

//Get rid of last character, either & or ? if you have no $_GET values yet
$Path = substr($Path, 0, -1);

//Add your new variables here
$Path .= "val1=a&val2=b";

//And then $Path with be your new URL!

Link to comment
Share on other sites

Ok try this (added some things to Garethp's):

 

//Base reference, the page you are on now
$Path = "index.php?";

//keep track of how many gets you've added on
$x = 0;

//Loop through all the $_GET value in your URL already
foreach($_GET as $k => $v)
{
   //Add them to path again
   $Path .= $k . "=" . $v . "&";
   //increment x everything you add a GET variable on
   $x++;
}

//Get rid of last character, either & or ? if you have no $_GET values yet
$Path = substr($Path, 0, -1);

//if x == 0 use ? if not use &
$Path .= ($x == 0) ? "?coverage=more" : "&coverage=more";

//And then $Path with be your new URL!
read more

Link to comment
Share on other sites

thanks, but should i add this code to index.php or to balkanesports.php page?

 

i tried to add it on "balkanesports.php"  on the place where link should go,

 

i pasted this:

 

<? //Base reference, the page you are on now
$Path = "index.php?";

//keep track of how many gets you've added on
$x = 0;

//Loop through all the $_GET value in your URL already
foreach($_GET as $k => $v)
{
   //Add them to path again
   $Path .= $k . "=" . $v . "&";
   //increment x everything you add a GET variable on
   $x++;
}

//Get rid of last character, either & or ? if you have no $_GET values yet
$Path = substr($Path, 0, -1);

//if x == 0 use ? if not use &
$Path .= ($x == 0) ? "?coverage=balkanesports2" : "&coverage=balkanesports2";

//And then $Path with be your new URL!
<a href="<?php $_SERVER['PHP_SELF'] . $Path; ?>">read more</a>?> 

Link to comment
Share on other sites

Should be whatever page you want the LINK to show up on.  Sorry, use this code, I forgot to close the PHP tags in my previous post.  (Side note: Never use short tags, , always use, <?php)

 

//Base reference, the page you are on now
$Path = "index.php?";

//keep track of how many gets you've added on
$x = 0;

//Loop through all the $_GET value in your URL already
foreach($_GET as $k => $v)
{
   //Add them to path again
   $Path .= $k . "=" . $v . "&";
   //increment x everything you add a GET variable on
   $x++;
}

//Get rid of last character, either & or ? if you have no $_GET values yet
$Path = substr($Path, 0, -1);

//if x == 0 use ? if not use &
$Path .= ($x == 0) ? "?coverage=balkanesports2" : "&coverage=balkanesports2";

?>

//And then $Path with be your new URL!
read more

Link to comment
Share on other sites

I'm really off today.  I forgot to echo the variable in the HTML link.  Try this:

 

//Base reference, the page you are on now
$Path = $_SERVER['PHP_SELF'] . "index.php?";

//keep track of how many gets you've added on
$x = 0;

//Loop through all the $_GET value in your URL already
foreach($_GET as $k => $v)
{
   //Add them to path again
   $Path .= $k . "=" . $v . "&";
   //increment x everything you add a GET variable on
   $x++;
}

//Get rid of last character, either & or ? if you have no $_GET values yet
$Path = substr($Path, 0, -1);

//if x == 0 use ? if not use &
$Path .= ($x == 0) ? "?coverage=balkanesports2" : "&coverage=balkanesports2";

echo $Path;

//And then $Path with be your new URL!  ?>
read more

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.