/    Sign up×
Community /Pin to ProfileBookmark

[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.

[code=php]<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>[/code]

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@tirnaJul 28.2010 — 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.
Copy linkTweet thisAlerts:
@OctoberWindJul 28.2010 — one of mt favorite uses for a ternary.

(assuming $info['Teams'] is 9/jv/v:
[code=php]
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>";
}
[/code]


then as Tirna suggested, you can create a css style

[code=html]
<style type="text/css">
tr.varsity {
background-color: #444;
color: #c00;
}
</style>
[/code]


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.

[code=php]
$varsity = ($info['Teams'] == "9") ? ' class="nine" ' : '' ;
$varsity = ($info['Teams'] == "jvarsity") ? ' class="jvarsity" ' : '' ;
$varsity = ($info['Teams'] == "varsity") ? ' class="varsity" ' : '' ;
[/code]
Copy linkTweet thisAlerts:
@phpkyle92authorJul 28.2010 — Thanks! This worked like a charm! Really appreciate everyone's help!
×

Success!

Help @phpkyle92 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...