Irish SEO,  Marketing & Webmaster Discussion

 

dynamic css

This is a discussion on dynamic css within the Coding Help forums, part of the Webmaster Help category; im working on a video on demand project which is built which php, html, javscript and mysql as well as ...


Go Back   Irish SEO, Marketing & Webmaster Discussion > Webmaster Help > Coding Help

Register Forum Rules FAQDonate Members List Calendar Search Today's Posts Mark Forums Read


Notices

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-10-2006, 11:01 AM
7aken's Avatar
Frontpage User
 
Join Date: Oct 2006
Posts: 23
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
7aken will become famous soon enough
Default dynamic css

im working on a video on demand project which is built which php, html, javscript and mysql as well as some other scripting. im wont get into the workings of the system but i need help figuring out a small matter.

im currently working on the cms which will handle amongst other things, the ability for the front desk to be able to change the style of the product. this kind of change will most likely only happen once, when the product is implemented in the clients premises but the ability to change between styles must remain. i can use javascript but its glitchy and i need a solid solution. so my thinking is to use dynamic css. ive been reading how to do this but cant find the solution i need. as mentioned, the front office who will be administering the system with the cms, need to be able to change the style of the pages which will be delivered. as such, there has to be a form to be able to switch styles as well as a folder holding my styles.

the bit i cant figure out is how best to call the css to the page once its selected. im currently tricking with the following which as it is, is not working as in the html displays minus the css. this is just experimental code. html form is first and is called styles.htm

Code:
<html>
<head></head>
<body>
<form action="start.php" method="post">
What stylesheet would you like to use? <input type="text" name="msg" size="30">
<input type="submit" value="send">
</form>
</body>
</html>
the actual page is then called start.php

PHP Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>video service</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" media="all">
<?php
$style
=$_POST['msg'];
if (
$style == "style1"){
echo 
"
 @import \"css/main.css\"\;
 body {
 background-color: #FFFFFF;
 background-image: url(images/bg1.png);
}
"
;} elseif ($style == "style2") {
  echo 
"
  @import \"css/main2.css\"\;
  body {
    background-color: #ffffff;
    }"
;}
?>
</style>
</head>
<body>
<div id="page">
<div id="head" height="100%"><h1>
  <p> ..........this is the header div</p>
  </h1>
</div>
<div id="content" height="100%"><h1><br>
  ..........Content div</h1>
  <h1>&lt;---&lt;--- will need border <br>
      <br>
      <br>
      <br>
      <br>
      <br>
      <br>
      <br>
      <br>
  </h1>
</div>
<div id="foot" height="100%"><h1>
  <p>.....this is the foot div</p>
</h1>
</div>
</div>
</body>
</html>
so has anyone done this or does anyone know the correct way to do it? im going to trick around with a switch which ive been creating but have already been having problems with. ie my form cant seem to pull data from the switch

ps i dont want to use cookies or a session. this has to be permanent until its changed by the front office

Last edited by 7aken; 09-10-2006 at 11:14 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #2 (permalink)  
Old 09-10-2006, 12:14 PM
louie's Avatar
Senior Member
 
Join Date: Jan 2006
Location: Dublin, Ireland
Posts: 2,010
Nominated 5 Times in 3 Posts
TOTW/F/M Award(s): 0
louie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud of
Send a message via Yahoo to louie Send a message via Skype™ to louie
Default

First create the select menu.
Code:
<select name='style' id='style'>
<option value='_1'>style 1</option>
<option value='_2'>style 2</option>
</select>
then create the php code
Code:
<?php
$style_set = "_1";//set the default
if(@$_REQUEST['style'] <> ""){
  $style_set = $_REQUEST['style'];
  $_SESSION['set_style'] = $style_set;
  header("Location: ".$_SERVER['PHP_SELF']);//redirect so we can show the changes to the style
}
if(isset($_SESSION['set_style'])){$style_set = $_SESSION['set_style'];}
//set style if session isset
?>
then you have your stylesheet included
Code:
<?php
echo "<link rel=\"stylesheet\" href=\"style$style_set.css\" media=\"all\" />";
?>
if you don't want to use sessions or cookie store the value from the form in the database, then have a recordset pulling the data and set the
Code:
$style_set = rs['style'];
__________________
:. Web Design & Development Web Design Ireland
:. Search Engines Optimization Search Engines Optimization
:. Directory Submission Directory Submission
:. News & Press Release Ireland GiveItSocks.com
:. Used Cars Ireland, Car Parts & Car Audio Cars For Sale, Car Parts & Accessories
:. I Have 2 Find It Directory SEF Directory

Last edited by louie; 09-10-2006 at 12:53 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3 (permalink)  
Old 09-10-2006, 12:37 PM
7aken's Avatar
Frontpage User
 
Join Date: Oct 2006
Posts: 23
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
7aken will become famous soon enough
Default

hi louie,

im trying to implement the code you provided (many thanks) but it doesnt seem to work, i think my structure is wrong, exactly what should go where?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4 (permalink)  
Old 09-10-2006, 12:40 PM
louie's Avatar
Senior Member
 
Join Date: Jan 2006
Location: Dublin, Ireland
Posts: 2,010
Nominated 5 Times in 3 Posts
TOTW/F/M Award(s): 0
louie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud of
Send a message via Yahoo to louie Send a message via Skype™ to louie
Default

show me what you have and i'll take a look at it
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5 (permalink)  
Old 09-10-2006, 12:53 PM
louie's Avatar
Senior Member
 
Join Date: Jan 2006
Location: Dublin, Ireland
Posts: 2,010
Nominated 5 Times in 3 Posts
TOTW/F/M Award(s): 0
louie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud of
Send a message via Yahoo to louie Send a message via Skype™ to louie
Default

have a look here:

Code:
<?php session_start(); 
ob_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="XHTML namespace">
<?php
$style_set = "_1";//set the default
if(@$_REQUEST['style'] <> ""){
  $style_set = $_REQUEST['style'];
  $_SESSION['set_style'] = $style_set;
  header("Location: ".$_SERVER['PHP_SELF']);//redirect so we can show the changes to the style
}
if(isset($_SESSION['set_style'])){$style_set = $_SESSION['set_style'];}
//set style if session isset
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<?php
echo "<link rel=\"stylesheet\" href=\"style$style_set.css\" media=\"all\" />";
?>
</head>
<body>
<form name="select_style" action="x_style_set.php" method="post">
 <select name="style" onChange='this.form.submit();'>
  <option value='_1' <?php if($style_set == "_1"){echo "selected";}?>>style 1</option>
  <option value='_2' <?php if($style_set == "_2"){echo "selected";}?>>style 2</option>
 </select>
</form>
<?php echo "your style that you have selected is - <b>style$style_set.css</b>";?>
</body>
</html>

Last edited by louie; 10-10-2006 at 08:12 AM. Reason: added code
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6 (permalink)  
Old 10-10-2006, 06:09 AM
7aken's Avatar
Frontpage User
 
Join Date: Oct 2006
Posts: 23
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
7aken will become famous soon enough
Default

hey louie,

i figured it from the info you provided... many thanks. I didnt post my existing code because im 3 hours ahead of you and had left the office before you responded!! cheers
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7 (permalink)  
Old 10-10-2006, 08:13 AM
louie's Avatar
Senior Member
 
Join Date: Jan 2006
Location: Dublin, Ireland
Posts: 2,010
Nominated 5 Times in 3 Posts
TOTW/F/M Award(s): 0
louie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud of
Send a message via Yahoo to louie Send a message via Skype™ to louie
Default

you are welcome.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
css, dynamic

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads

Thread Thread Starter Forum Replies Last Post
How to make a H1 tag in CSS into a link shanediffily Coding Help 4 10-10-2006 04:54 PM


All times are GMT +1. The time now is 06:32 AM.


Powered by: vBulletin Version 3.7.3, Copyright ©2000 - 2008, Jelsoft Enterprises Limited.
Hosted in Ireland by Blacknight - Test your ISP |Irish Hosting Directory| Armchair.ie|Logo by Eden Web Design|Avatars by Afterglow |Latest Blog Entries | VPS HostingAd Management by RedTyger

Search Engine Friendly URLs by vBSEO 3.2.0