Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Oct 2005
    Posts
    61
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Change cell background

    from my mysql database, i have a cell which have words as green, yellow as results.

    i was wondering, how could i change that cell background based on the word i get.


    thank you

  • #2
    Senior Coder DJCMBear's Avatar
    Join Date
    Mar 2010
    Location
    United Kindom
    Posts
    1,173
    Thanks
    14
    Thanked 136 Times in 136 Posts
    Quote Originally Posted by pagedrop View Post
    from my mysql database, i have a cell which have words as green, yellow as results.

    i was wondering, how could i change that cell background based on the word i get.


    thank you
    have a mysql query with somthing like this assuming you want a random color to be called and not alternative colours
    PHP Code:
    $result=mysql_query("SELECT * FROM table ORDER BY REAND() LIMIT 0,1");
    while(
    $row mysql_fetch_array($result)){
    $color $row['collname'];
    print 
    "<td style=\"background-color:$color;\"></td>\n";

    Official BinPress hand picked coder.
    For anyone worried about SQL injection go have a look at my small yet powerful script here.
    Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
    I am 1 of 65,608 people to get a Pebble Watch :P

  • #3
    New Coder
    Join Date
    Oct 2005
    Posts
    61
    Thanks
    12
    Thanked 0 Times in 0 Posts
    didnt quite help, i need to show green color, if the results from column"Risk" is green, and yellow background if its yellow in that column. etc..

  • #4
    Senior Coder DJCMBear's Avatar
    Join Date
    Mar 2010
    Location
    United Kindom
    Posts
    1,173
    Thanks
    14
    Thanked 136 Times in 136 Posts
    Ok then heres the code:
    PHP Code:
    $result=mysql_query("SELECT * FROM table");
    if(
    mysql_num_rows($result)){
    while(
    $row mysql_fetch_array($result)){
    $risk strtolower($row['Risk']);
    if(
    $risk=='yellow'){
    $color '#FFFF00';
    }elseif(
    $risk=='green'){
    $color '#33CC33';
    }else{
    $color '';
    }}}
    print 
    $color
    Official BinPress hand picked coder.
    For anyone worried about SQL injection go have a look at my small yet powerful script here.
    Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
    I am 1 of 65,608 people to get a Pebble Watch :P

  • #5
    New Coder
    Join Date
    Jan 2011
    Location
    Bangladesh
    Posts
    73
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by DJCMBear View Post
    Ok then heres the code:
    PHP Code:
    $result=mysql_query("SELECT * FROM table");
    if(
    mysql_num_rows($result)){
    while(
    $row mysql_fetch_array($result)){
    $risk strtolower($row['Risk']);
    if(
    $risk=='yellow'){
    $color '#FFFF00';
    }elseif(
    $risk=='green'){
    $color '#33CC33';
    }else{
    $color '';
    }}}
    print 
    $color
    hi i have same question, my data are in number like 0,1,2,5,30,100,200 and so on,i want cell bgcolor in red where data equal or below 30 and data equal or below 60 in yellow and others in green color, plz help me. My colum name is "days to go".


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •