Results 1 to 9 of 9

Thread: Row Color Question

  1. #1
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Row Color Question

    Ok, I am making a script for support tickets, and I want the cell that has the ticket status (low, medium, high, urgent) in it to show up a different color depending on its urgency. I am trying to do this by using the urgency column from the sql table. Here is how I am trying to do it:
    PHP Code:
    // For each result found
    while($row mysql_fetch_array($result)) {
        
    extract($row);
        
    echo 
    '
            <tr>
                <td>'
    .$id.'</td>
                <td><a href="index.php?page=view&id='
    .$id.'">'.$subject.'</a></td>
                <td style="background-color: '
    .$color.'">'.$urgency.'</td>
                <td>'
    .$date.'</td>
                <td><input type="checkbox" name="checkbox[]" value="'
    .$id.'" /></td>
                <td>'
    .$status.'</td>
            </tr>'
    ;
            
        
    // Get status color 
            
    if($urgency == "low") {
                
    $color == "#F19F00";
            }
            if(
    $urgency == "medium") {
                
    $color == "#EC7501";
            }
            if(
    $urgency == "high") {
                
    $color == "#EC3801";
            }
            if(
    $urgency == "urgent") {
                
    $color == "#FF0000";
            }

    I am not sure if that way will work correctly or not, but as of now the color does not show up. I appreciate any help
    Thanks DD, you saved me countless times

  2. #2
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    I'm assuming you haven't defined all of your variables for the rows, and that's probably why it won't work:

    Make sure you define them:

    id might be
    PHP Code:
    $id mysql_result($result,$i,"id"); 
    and do that with the other undefined variables.
    For that to work you must use an iterator in your while loop:
    PHP Code:
    $i 0;
    while(
    $row mysql_fetch_array($result)) {
        
    extract($row);
        
    echo 
    '
            <tr>
                <td>'
    .$id.'</td>
                <td><a href="index.php?page=view&id='
    .$id.'">'.$subject.'</a></td>
                <td style="background-color: '
    .$color.'">'.$urgency.'</td>
                <td>'
    .$date.'</td>
                <td><input type="checkbox" name="checkbox[]" value="'
    .$id.'" /></td>
                <td>'
    .$status.'</td>
            </tr>'
    ;
            
        
    // Get status color 
            
    if($urgency == "low") {
                
    $color == "#F19F00";
            }
            if(
    $urgency == "medium") {
                
    $color == "#EC7501";
            }
            if(
    $urgency == "high") {
                
    $color == "#EC3801";
            }
            if(
    $urgency == "urgent") {
                
    $color == "#FF0000";
            }
            
    i++;

    - Mike

  3. #3
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Actually, if you just want to make the row color based upon what the urgency is, you don't need anything special other than the code snippet below:

    Code:
    while($row = mysql_fetch_array($result)) {
        extract($row);
    
    
           // Get status color 
            if($urgency == "low") {
                $color == "#F19F00";
            }
            if($urgency == "medium") {
                $color == "#EC7501";
            }
            if($urgency == "high") {
                $color == "#EC3801";
            }
            if($urgency == "urgent") {
                $color == "#FF0000";
            }
     
    
    echo '
            <tr>
                <td>'.$id.'</td>
                <td><a href="index.php?page=view&id='.$id.'">'.$subject.'</a></td>
                <td style="background-color: '.$color.'">'.$urgency.'</td>
                <td>'.$date.'</td>
                <td><input type="checkbox" name="checkbox[]" value="'.$id.'" /></td>
                <td>'.$status.'</td>
            </tr>';
            
    }
    Notice how I define the color variable before I display the information.

    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  4. #4
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I tried both ways and both were unsuccessful. It just doesn't get the color value. Any ideas?
    Thanks DD, you saved me countless times

  5. #5
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    I just noticed (sorry, my daughter woke me up extremely early this morning) the following part

    Code:
    $color == "#F19F00";
    should be
    Code:
    $color = "#F19F00";
    Notice one equal sign ( = )

    That should do it
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  6. #6
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    The = sign was it! Thanks a ton. Howcome the double "=" was making it mess up?
    Thanks DD, you saved me countless times

  7. #7
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    When you use double equal signs, it means you are comaring something:

    Code:
    if ($urgency == "low")
    That compares the value of urgency to something else ("low"). A single equal sign defines something:

    Code:
    $color = #000000;
    Hope that helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  8. #8
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Ah yes, a common mistake to overlook the to operators.
    == is a comparison operator
    = is an assigning operator
    === assigns/compares the string/number based on the result
    - Mike

  9. #9
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks for the help, its working great
    Thanks DD, you saved me countless times

Bookmarks

Posting Permissions

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