Jump to content

Basic PHP $_GET help + Basic Navigation.


RuSty

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.