March 23rd, 2002, 11:51 AM
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?
March 23rd, 2002, 10:26 PM
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.
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,
This is me: http://chris.uk.com
March 24th, 2002, 07:01 AM
You may/may not find it of use, but I thought it was worth mentioning.
March 24th, 2002, 11:16 AM
found a solution
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).