RuSty Posted August 18, 2007 Share Posted August 18, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/65552-basic-php-_get-help-basic-navigation/ Share on other sites More sharing options...
marcus Posted August 18, 2007 Share Posted August 18, 2007 Um, use the file name instead of just adding on. So instead of: &style=blue Use: index.php?page=services&style=blue Quote Link to comment https://forums.phpfreaks.com/topic/65552-basic-php-_get-help-basic-navigation/#findComment-327315 Share on other sites More sharing options...
RuSty Posted August 18, 2007 Author Share Posted August 18, 2007 but with a URL such as: index.php?page=services&style=blue is there any way to change $_GET['page'] but not $_GET['style'] So if a user clicks on contact, the 'style' wont change but the 'page' will? Quote Link to comment https://forums.phpfreaks.com/topic/65552-basic-php-_get-help-basic-navigation/#findComment-327317 Share on other sites More sharing options...
marcus Posted August 18, 2007 Share Posted August 18, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/65552-basic-php-_get-help-basic-navigation/#findComment-327320 Share on other sites More sharing options...
RuSty Posted August 18, 2007 Author Share Posted August 18, 2007 Thank you very much mgall, I'll test everything and post back this afternoon. -Rus Quote Link to comment https://forums.phpfreaks.com/topic/65552-basic-php-_get-help-basic-navigation/#findComment-327464 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.