Jump to content

Recommended Posts

Ok, so I am re-learning php and I am having some trouble using $_GET variables.

 

I want to use it for two things:

1. dynamic content - ie when a user clicks of "services" the url will be www.sitename.com/index.php?page=services

2. dynamic styles - so when a user clicks on a provided "color box" the website will reskin itself accordingly.

 

so in otherwords a desired url could be:

www.sitename.com/index.php?page=services&style=blue

 

How I have it setup right now is by having the navigation menu buttons just link like this < a href="index.php?page=services"></a>

 

and then i tried setting up the styles like this:

 

<a href="<?php $url . "&style=blue" ?>"></a>

and it worked fine except an obvious problem, if you clicked the button twice the url would read:

www.sitename.com/index.php?page=services&style=blue&style=blue

 

 

So does anyone know a more effecient way of doing this?

 

 

 

Thank you,

-RuSty

Link to comment
https://forums.phpfreaks.com/topic/65552-basic-php-_get-help-basic-navigation/
Share on other sites

You could try this:

 

<?php
$page = $_GET['page'];
$style = $_GET['style'];
$pages = array('your','page','names');

foreach($pages AS $links){
if($page){
	if($links == $page){
	$url = "$links<br>\n";
	}else {
	$url = "<a href=\"index.php?page=$link&style=$style\">$links</a><br>\n";
	}
}else {
$url = "<a href=\"index.php?page=$link&style=$style\">$links</a><br>\n";
}
echo $url;
}
?>

 

*TESTED* works fine.

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.