suess0r Posted December 22, 2006 Share Posted December 22, 2006 Hi there, i want to have an option for a user to change colors/themes on my page... it works fine, but it's just running really slowwww... i was wondering if there was a way to optimize this code??i'm using a GET on the same page (ie: if they click the orange color it sends to (pgg.php?c=o), etc.) like i said it works, just wondering if there was anything i could do to make it run faster? i know i could use switches on the if statements but that wouldn't slow it up that much would it?<?php $theme = $_GET["c"]; if (!isset($theme)){ echo '<link rel="stylesheet" type="text/css" href="default.css" media="screen"/>'; } if ($theme == "g"){ echo '<link rel="stylesheet" type="text/css" href="default.css" media="screen"/>'; } if ($theme == "b"){ echo '<link rel="stylesheet" type="text/css" href="blue.css" media="screen"/>'; } if ($theme == "p"){ echo '<link rel="stylesheet" type="text/css" href="pink.css" media="screen"/>'; } if ($theme == "o"){ echo '<link rel="stylesheet" type="text/css" href="orange.css" media="screen"/>'; } ?><title>CLB 411 - Search</title><style type="text/css"><!--.style2 { font-size: 1.2em; color: #FFFFFF;}--></style>[quote] <?php $theme = $_GET["c"]; if (!isset($theme)){ echo '<link rel="stylesheet" media="all" type="text/css" href="final_drop.css" />'; } if ($theme == "g"){ echo '<link rel="stylesheet" media="all" type="text/css" href="final_drop.css" />'; } if ($theme == "b"){ echo '<link rel="stylesheet" media="all" type="text/css" href="blue_drop.css" />'; } if ($theme == "p"){ echo '<link rel="stylesheet" media="all" type="text/css" href="pink_drop.css" />'; } if ($theme == "o"){ echo '<link rel="stylesheet" media="all" type="text/css" href="orange_drop.css" />'; } ?>[/quote] Quote Link to comment https://forums.phpfreaks.com/topic/31614-color-changing-options-switching-csss/ Share on other sites More sharing options...
papaface Posted December 22, 2006 Share Posted December 22, 2006 I personally would do something like:[code]switch ($_GET["style"]){case "1":$stylesheet = "style1.css";case "2":$stylesheet = "style2.css";default:$stylesheet = "style1.css";}echo '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'" media="screen"/>';[/code] Quote Link to comment https://forums.phpfreaks.com/topic/31614-color-changing-options-switching-csss/#findComment-146525 Share on other sites More sharing options...
suess0r Posted December 22, 2006 Author Share Posted December 22, 2006 Thanks for the help, question about the code though....i dunno if i'm doing this right because it's not passing the css right... [quote]switch ($_GET["c"]){case "g":$theme = "default.css";case "b":$theme = "blue.css";case "p":$theme = "pink.css";case "o":$theme = "orange.css";default:$theme = "default.css";}echo '<link rel="stylesheet" type="text/css" href="'.$theme.'" media="screen"/>';[/quote]I want it to be equivelant to this code...[quote]$theme = $_GET["c"]; if (!isset($theme)){ echo '<link rel="stylesheet" type="text/css" href="default.css" media="screen"/>'; } if ($theme == "g"){ echo '<link rel="stylesheet" type="text/css" href="default.css" media="screen"/>'; } if ($theme == "b"){ echo '<link rel="stylesheet" type="text/css" href="blue.css" media="screen"/>'; } if ($theme == "p"){ echo '<link rel="stylesheet" type="text/css" href="pink.css" media="screen"/>'; } if ($theme == "o"){ echo '<link rel="stylesheet" type="text/css" href="orange.css" media="screen"/>'; }[/quote] Quote Link to comment https://forums.phpfreaks.com/topic/31614-color-changing-options-switching-csss/#findComment-146595 Share on other sites More sharing options...
Philip Posted December 22, 2006 Share Posted December 22, 2006 You need the breaks in the switch:[code]<?phpswitch ($_GET["c"]){case "g":$theme = "default.css";break;case "b":$theme = "blue.css";break;case "p":$theme = "pink.css";break;case "o":$theme = "orange.css";break;default:$theme = "default.css";break;}echo '<link rel="stylesheet" type="text/css" href="'.$theme.'" media="screen"/>';?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/31614-color-changing-options-switching-csss/#findComment-146603 Share on other sites More sharing options...
trq Posted December 22, 2006 Share Posted December 22, 2006 You need to use a break after each case. eg;[code]<?phpswitch ($_GET["c"]) { case "g": $theme = "default.css"; break; case "b": $theme = "blue.css"; break; case "p": $theme = "pink.css"; break; case "o": $theme = "orange.css"; break; default: $theme = "default.css"; break;}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/31614-color-changing-options-switching-csss/#findComment-146604 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.