#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2002
    Location
    Salem, NH
    Posts
    10
    Rep Power
    0

    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. #2
  3. Introspective
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Nov 2001
    Location
    London, UK
    Posts
    3,317
    Rep Power
    110
    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
    This is me: http://chris.uk.com
  4. #3
  5. superficial
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2002
    Location
    Peterborough, England
    Posts
    188
    Rep Power
    13
    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
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2002
    Location
    Salem, NH
    Posts
    10
    Rep Power
    0

    Talking 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).

IMN logo majestic logo threadwatch logo seochat tools logo