Link to home
Start Free TrialLog in
Avatar of tprofits
tprofits

asked on

How can I change a div tag background color based on a database entry?

I am using PHP to populate a MySQL database with either 'yes', 'maybe', or 'no'.  I want a CSS div tag to change color based on the database entry.  For example:

if 'yes' >> green
if 'maybe' >> yellow
if 'no' >> red

I'm not sure where to start.
Avatar of kevp75
kevp75
Flag of United States of America image

Do have existing code... please post it
Avatar of tprofits
tprofits

ASKER

I have my div tags:
<body>
<div id="weekend_avail">Jon</div>
<div id="weekend_avail">Mike</div>
<div id="weekend_avail">Scott</div>
<div id="weekend_avail">Todd</div>
</body>

I want my CSS background-color to change to #00FF00, #FFFF00, or #FF0000 based on whether the MySQL database is populated with 'yes', 'no', or 'maybe':
<head>
<style type="text/css">
<!--
#weekend_avail {
      width: 300px;
      height: 15px;
      font-size: 12px;
      background-color: #FFFFFF;
}
-->
</style>
</head>
ASKER CERTIFIED SOLUTION
Avatar of shobinsun
shobinsun
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yes. Yes.  That makes sense!  I'll try that out in the morning.
Got me going in the right direction.  Worked nicely.