change color of list elements according to condition

后端 未结 1 643
隐瞒了意图╮
隐瞒了意图╮ 2020-12-12 04:24

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 T

相关标签:
1条回答
  • 2020-12-12 04:45

    1) Join the the queries into one

    select EmployeeTable.*,Table2.pointsRewarded as `weeklyDelta`
    from EmployeeTable join Table2 on EmployeeTable.EmployeeID = Table2.EmployeeID
    where Table2.WeekNumber = 'week1'
    order by Total_points_Rewarded desc
    

    2) Then give the employees with negative deltas a special class

    <?php  
    while( $toprow2 = sqlsrv_fetch_array( $stmt3) ) {
        echo  "<div class='parent-div" .
            ($toprow2['weeklyDelta'] <= -10 ? " dropped" : "") .
            "'><span class='rank'>" .
            $toprow2['overallRank'] . "</span><span class='name'>" . 
            $toprow2['EmployeeName'] . "</span><span class='points'>" . 
            $toprow2['Total_points_Rewarded'] . "</span></div>";
    } ?>
    

    3) give those employees a style

    .parent-div.dropped { color:red }
    
    0 讨论(0)
提交回复
热议问题