|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
pass variables to css?
im using php and mysql. i have a standard css and wish to manipulate the css on the fly based on variables that i will populate via the database then pass to the css ... how can i get my php variables passed to the css?
|
|
#2
|
||||
|
||||
|
You could use PHP's file maniupulation functions to open and read the contents of your .css, and then use regexps to parse those contents, making any alterations you want - and then rebuild the file. BUT don't forget that this will affect all users who are viewing pages which <link> this .css file in... maybe that's your intention. I don't know.
Probably the fastest method would be to use some client-side DHTML, so if you have an input box, say, with an id of "myInput", you could send up a javascript array of variables produced by your PHP, and then adjust it's style properties like this: document.getElementById("myInput").style.selector =value where selector might be 'color' value could be "blue" If you do it this way, other people looking at the pages will still get the original style definitions until they run a db query and a new one is set. Not sure if that's any help, Hope so Christo
__________________
. Spiration channels: Free scripts, programming tutorials and articles Dotcut alerts: Online Press cuttings / news alerts Clearprop: UK microlight school, wiltshire Uk dating: UK safe dating with Topdates About Christo . . |
|
#3
|
||||
|
||||
|
There is a script which does this in JavaScript, its not php but it does allow you to switch stylesheets on the fly.
You may/may not find it of use, but I thought it was worth mentioning. http://www.alistapart.com/stories/alternate/ matt
__________________
_______________ Matt |
|
#4
|
|||
|
|||
|
thanks matt and cristo for your assistance. (i actually was on matt's site yesterday in my search for the solution). we are using a single architecture for multiple sites and all content etc is fed via the db. we want to have variation in styles for each individual site(and not have to maintain the .css for each), and therefore we setup a table that holds all the .css criteria and provide a backend management tool for the customer to be able to chage/modify it.
What i came up with was to query the database upon entry to the site, gather all style criteria, then write the custom .css file on the fly, save to server, and you are set (all in php and mysql). |
![]() |
| Viewing: Dev Shed Forums > Web Design > CSS Help > pass variables to css? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|