Change background color according to sql entry

Anything questions related to styling should go in here.
Post Reply
Smithers
Posts: 8
Joined: Mon Feb 06, 2012 3:09 pm

Change background color according to sql entry

Post by Smithers »

Hello,
I was wondering if it's possible to change the background color of a page depending on the sql entry. For example if I have 3 sql entries: 1 is drinking, 2 is eating, 3 is sleeping; the user chooses drinking, he will see the page in blue, he chooses sleeping, it would be red. I would be very grateful for any help.
Many Thanks
ExtremeGaming
Posts: 205
Joined: Mon Jul 09, 2012 11:13 pm

Re: Change background color according to sql entry

Post by ExtremeGaming »

You will need to query your database, and then just use the info to change the css in the head according to the results.

[syntax=php]<?php
// $row is from mysql_fetch_something()
// And of course you would have a default theme using else, but this is just an example
if($row['theme'] == "sleeping") { $color = "red"; }
?>

<style>
body { background-color: <?php echo $color; ?> }
</style>[/syntax]
<?php while(!$succeed = try()); ?>
Post Reply