I have many Themes in my Themes folder. What is the idea of changing theme through database. I mean is it possible to pickup one of theme from database?.
Thank you in advance
I have many Themes in my Themes folder. What is the idea of changing theme through database. I mean is it possible to pickup one of theme from database?.
Thank you in advance
Well, the following code isn't exactly for a database but then I don't know why you'd want a database if you're going to be using stylesheets, why not just have them in a folder called "Themes" and then allow the user to select from one of them. Please try and explain how the database will be helpful in this situation.
Anyway, here's a simple style changer:
PHP Code:<?php
if (isset($_GET['theme']))
{
$theme = $_GET['theme'];
switch ($theme)
{
case 1:
$theme = 1;
break;
case 2:
$theme = 2;
break;
case 3:
$theme = 3;
break;
case 4:
$theme = 4;
break;
default:
$theme = 1;
}
}
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="theme<?php if(isset($theme)) { echo "$theme";} ?>.css"/>
</head>
<body>
<form action="themes.php" method="get">
<select name="theme">
<option value="1">Theme 1</option>
<option value="2">Theme 2</option>
<option value="3">Theme 3</option>
<option value="4">Theme 4</option>
</select><p></p>
<input type="submit" value="Select"/>
</form>
</body>
</html>
Better:Schmoopy, watch that pseudo-XHTML.Code:<?php session_start(); $themes = array( 'red' => 'Red', 'greenish' => 'Green/Blue', 'transparent' => 'Glass', 'fish' => 'Sea Life', 'grass' => 'Natural' ); $defaultTheme = @$_POST['theme']; if (!isset($themes[$defaultTheme])) $defaultTheme = key($themes); $_SESSION['preferred_theme'] = $defaultTheme; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <link rel="stylesheet" type="text/css" href="<?php echo $defaultTheme; ?>"> <?php foreach ($themes as $file => $title): ?> <link rel="alternate stylesheet" type="text/css" href="<?php echo $file; ?>.css" title="<?php echo $title; ?>"> <?php endforeach; ?> </head> <body> <form action="<?php echo $_SERVER['REQUEST_URI']; ?>"> <div> <select name="theme"> <?php foreach ($themes as $file => $title): ?> <option value="<?php echo $file; ?>"> <?php echo $title; ?> </option> <?php endforeach; ?> </select> <input type="submit" value="Select"> </div> </form> </body> </html>
Last edited by Twey; 01-24-2009 at 10:16 PM.
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
You mean the /> at the end of tags?![]()
Yes. In HTML, that technically ought to leave > characters scattered all over your page.
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
Thank you so much friends for your help
you are No. 1
Bookmarks