TR World Posted March 29, 2010 Share Posted March 29, 2010 Hey! I was wondering if there's is a way in Php of I could, use some code to switch stylesheets? e.g. if you go to http://trsearch.org they let you choose a different template from a drop-done list a the bottom. How do they do this? Help! Link to comment https://forums.phpfreaks.com/topic/196847-template-switcher/ Share on other sites More sharing options...
zendoctor Posted March 29, 2010 Share Posted March 29, 2010 Create a dropdown box with the template names and when selected update a database field for that user with the template name and link to css file. Have a file which fetch the user or session preferences require(preferences.php); which runs a query to get the stylesheet location for that user or session and assign it to a session variable $stylesheet In your pages do something like <link rel="stylesheet" type="text/css" href="<?php echo $stylesheet; ?>" /> Link to comment https://forums.phpfreaks.com/topic/196847-template-switcher/#findComment-1033387 Share on other sites More sharing options...
TR World Posted March 29, 2010 Author Share Posted March 29, 2010 Okay I went through the php & sql tutorial on w3 schools. I'm new new to php/sql but I didn't understand what you said. Link to comment https://forums.phpfreaks.com/topic/196847-template-switcher/#findComment-1033394 Share on other sites More sharing options...
zendoctor Posted March 29, 2010 Share Posted March 29, 2010 Is the application for a user login or for visitors to a page to switch templates until the page is closed? Link to comment https://forums.phpfreaks.com/topic/196847-template-switcher/#findComment-1033396 Share on other sites More sharing options...
TR World Posted March 29, 2010 Author Share Posted March 29, 2010 no its just select a template you won't be able to log in. Link to comment https://forums.phpfreaks.com/topic/196847-template-switcher/#findComment-1033405 Share on other sites More sharing options...
TR World Posted March 29, 2010 Author Share Posted March 29, 2010 soory double post, Anyone?? Zendoctor? No you won't be able to log in to the site. Link to comment https://forums.phpfreaks.com/topic/196847-template-switcher/#findComment-1033418 Share on other sites More sharing options...
ChemicalBliss Posted March 29, 2010 Share Posted March 29, 2010 Start with your code, dont worry about the drop down box yet especially if your really new to php. To complete your idea you wil need to use: 1 or more IF Statements and implement sessions. Sessions: For every page that you want to store "User-Specific" data, (without them needing to log in), you use Sessions, and you must put "session_start();" at the top of your pages that use sessions. Once you do that you can save session variables between page clicks, unique to each user. For example: page1.php <?php session_start(); $_SESSION['test'] = "abc"; echo("<a href='page2.php'>See what happens:"); ?> page2.php <?php session_start(); echo("Previous Number: ".$_SESSION['test']"); ?> ======== Then the IF Statement: if.php <?php if($_SESSION['template'] == "template_1"){ echo("<stylesheet src="1..." />"); }else{ echo("<stylesheet src="2..." />"); } ?> ====== Now you can combine these to create a session enabled variable stylesheet template, hehe. If you want a drop-down box you need to create a php form script, these are very simple and can be added easily like so: form.php <form method="post" action="process.php"> <SELECT name="stylesheet"> <OPTION value="1">Some Style Name</OPTION> <OPTION value="2">Some Style Name 2</OPTION> <OPTION value="3">Some Style Name 3</OPTION> </form> process.php <?php // Check for the form submittion: if(isset($_POST['stylesheet'])){ $_SESSION['stylesheet'] = $_POST['stylesheet']; } ?> then, on each page where the stylesheet would be: <?php echo("<stylesheet src='path/to/styles/$_SESSION['stylesheet'].css'"); ?> Good Luck. -CB- Link to comment https://forums.phpfreaks.com/topic/196847-template-switcher/#findComment-1033494 Share on other sites More sharing options...
TR World Posted March 29, 2010 Author Share Posted March 29, 2010 Thanks! Link to comment https://forums.phpfreaks.com/topic/196847-template-switcher/#findComment-1033512 Share on other sites More sharing options...
khr2003 Posted March 29, 2010 Share Posted March 29, 2010 Why not simply your approach and use javascript: http://www.dynamicdrive.com/dynamicindex9/stylesheetswitcher.htm it is easier to implement, and neater. Link to comment https://forums.phpfreaks.com/topic/196847-template-switcher/#findComment-1033535 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.