Forum Moderators: not2easy

Message Too Old, No Replies

How to read values from database?

         

tntpower

9:33 am on Sep 18, 2009 (gmt 0)

10+ Year Member



I have a CSS file. Some values are editable by users. For example, uses can select their favorite background color and this color is stored in database.

I want some sort of placeholder in the CSS file so that when a user loads this page, the placeholder is replaced with the color user entered in database.

Can I do it?

rocknbil

2:58 pm on Sep 18, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



CSS is not dynamic, so no, not in the way you describe.

However ,you can do this

<link rel="stylesheet" type="text/css" href="/yourscript.cgi">
or
<link rel="stylesheet" type="text/css" href="/yourscript.asp">
or most likely,
<link rel="stylesheet" type="text/css" href="/yourscript.php">

where "yourscript" opens the css file with the markers, reads the database, and swaps out the markers for the user values. If you use this method, be sure your script outputs a content-type:text/css header.

Alternatively you can output the entire page(es) including the CSS and swap the user's values from the database on the fly. This might be better if there are in-page elements that are user-specific, which is likely.