www.webdeveloper.com
Results 1 to 4 of 4

Thread: [RESOLVED] Giving certain results a different color

  1. #1
    Join Date
    Jul 2010
    Posts
    9

    resolved [RESOLVED] Giving certain results a different color

    Hey everyone...

    I'm building a website for local sports in my community and will be doing schedules.

    High School sports usually have three different teams in the same sport, (9, JV, V). I would like to highlight all the Varsity (v) games with a different font color OR table background.

    PHP Code:
    <table width="100%">
    <tr>
    <td><strong>Date</strong></td><td><strong>Squad</strong></td><td><strong>Opponent</strong></td><td><strong>Time/Varsity Scores</strong></td><td><strong>Home/Away</strong></td>
    </tr>
    <?php
    // Connects to your Database
    mysql_connect("NOTHING TO SEE HERE""OR HERE""OR HERE") or die(mysql_error());
    mysql_select_db("OR HERE") or die(mysql_error());
    $data mysql_query("SELECT * FROM events WHERE Sport='$sport' and Team='$team'")
    or die(
    mysql_error());

    while(
    $info mysql_fetch_array$data ))
    {
    Print 
    "<tr><td>".$info['CleanDate'] . "</td><td>".$info['Teams'] . "</td><td>".$info['Opponent'] . "</td><td>".$info['TimeScore'] . "</td><td>".$info['HomeAway'] . "</td></tr>";
    }
    ?></table>

  2. #2
    Join Date
    Mar 2010
    Posts
    2,803
    One way to do it is to have a class name for each team and then give each <tr> the appropriate class name for the team data it is displaying and then set whatever styles you like for each class in your css.

  3. #3
    Join Date
    Jul 2007
    Location
    Wisconsin
    Posts
    468
    one of mt favorite uses for a ternary.

    (assuming $info['Teams'] is 9/jv/v:
    PHP Code:
    while($info mysql_fetch_array$data ))
    {
    $varsity = ($info['Teams'] == "varsity") ? ' class="varsity" ' '' 
    Print 
    "<tr $varsity><td>".$info['CleanDate'] . "</td><td>".$info['Teams'] . "</td><td>".$info['Opponent'] . "</td><td>".$info['TimeScore'] . "</td><td>".$info['HomeAway'] . "</td></tr>";

    then as Tirna suggested, you can create a css style

    HTML Code:
    <style type="text/css">
    tr.varsity {
    background-color: #444;
    color: #c00;
    }
    </style>
    Since you left the "or" part of the ternary blank, if it's not a varity team, there just wont be a class defined. You could also define a default style to put in there, or even stack the ternarys to color each team.

    PHP Code:
    $varsity = ($info['Teams'] == "9") ? ' class="nine" ' '' 
    $varsity = ($info['Teams'] == "jvarsity") ? ' class="jvarsity" ' '' 
    $varsity = ($info['Teams'] == "varsity") ? ' class="varsity" ' '' 

  4. #4
    Join Date
    Jul 2010
    Posts
    9
    Thanks! This worked like a charm! Really appreciate everyone's help!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles