I'm currently working on a project which will require a dynamic CSS file. I've decided that the best solution for this would be to create the CSS using PHP however I need the values to be retrieved from a database. The reason for this is that the information in the CSS file will be updated regularly based on user preferences. In order to make sure this is possible i've been conducting a series of small scale tests before developing my final product.
<?php
header("Content-Type: text/css");
// database connection
$result = mysql_query ("select css_value from test_data where css_id= '1' ");
$row = mysql_fetch_array($result);
$color = $row[css_value];
//$color = 'red';
?>
#test {
color: <?php echo $color; ?>
}
<?php
mysql_close($conn);
?>
When I manually set the $color variable then the CSS works exactly as desired, however any attempt to retrieve the variable from the database has no effect (i've tested that the variable can be retrieved). I'm curious as to whether what i'm attempting is possible or whether there has been a serious syntax error on my part (which is very likely as it's 2am and my brain is mushy from the flu). And I do appologise in advance for how silly this question may be if it is a syntax error, I have a bad habit of making really basic mistakes and spending hours stuck over them!!
If anybody could give me some advice that would be greatly appreciated!
regards,
Leanne

New Topic/Question
Reply




MultiQuote





|