Highlight A Box In A List According To A Condition In Another Table
I have two tables : Table 1 (overall Score ) Table 2 (weekly score ) I have a leaderboard where I am echoing the overall score value from Table 1 : Problem : What I am trying to
Solution 1:
By joining the two tables in the SQL statement, you could simplify the process. Use the code from dhi_m above, but the data would come from a single SQL query:
SELECT
`table1`.`EmployeeName`,
`table1`.`Overallpoints`,
`table1`.`overallRank`,
`table1`.`Total_points_Rewarded`,
IF(`Table2`.`points` = '-10','red-css-class','green-css-class') AS `display_status`
FROM `Table1`
LEFT JOIN `table2`
ON `table1`.`EmployeeID` = `table2`.`EmployeeID`
WHERE `table1`.`WeekNumber` = 'week1'
ORDER BY `Table1`.`Total_points_Rewarded` DESC
The HTML code for the list would then look something like:
<divid="overalllb"class="leadboardcontent"style="display:none"><divclass="leaderboard"><ol><li><mark><?phpwhile( $toprow2 = sqlsrv_fetch_array( $stmt3) ) {
echo"<div class='".$toprow2['display_status']."'><span class='rank'>" . $toprow2['overallRank'] . "</span><span class='name'>" . $toprow2['EmployeeName'] . "</span><span class='points'>" . $toprow2['Total_points_Rewarded'] . "</span></div>";
}
?></mark></li></ol></div></div>
(Not tested, may contain typos)
Solution 2:
You can check in a simple php if..else for highlighting it..
say you store specific score of user when inside users loop in $usersscore
if($usersscore<=-10){
$highlightclass="redmark";
}
else{
$highlightclass-"yellowmark";
}
In html inside class of html element you can echo it like
<liclass="<?phpecho$highlightclass; ?>">
Solution 3:
Please try this
<style>limarkdiv.parent-div-green {
display: block;
margin: 4px;
padding: 5px;
min-height: 50px;
border: 2px solid #eebb55;
border-radius: 7pt;
background: grey;
}
limarkdiv.parent-div-red {
display: block;
margin: 4px;
padding: 5px;
min-height: 50px;
border: 2px solid red;
border-radius: 7pt;
background: grey;
}
</style><divid="overalllb"class="leadboardcontent"style="display:none"><divclass="leaderboard"><ol><li><mark><?phpwhile( $toprow2 = sqlsrv_fetch_array( $stmt3) ) {
$divClass ="parent-div-green";
/****** Here write a query/function or join the two tables to fetch the Table2 $toprow2['EmployeeID']'s' `points` field value to the variable `$points` ********/if($points == -10) $divClass = "parent-div-red";
echo"<div class='".$divClass."'><span class='rank'>" . $toprow2['overallRank'] . "</span><span class='name'>" . $toprow2['EmployeeName'] . "</span><span class='points'>" . $toprow2['Total_points_Rewarded'] . "</span></div>";
}
?></mark></li></ol></div>
Post a Comment for "Highlight A Box In A List According To A Condition In Another Table"