根据另一个表中的条件突出显示列表中的框

时间:2017-01-05 06:54:55

标签: javascript php html css twitter-bootstrap

我有两张桌子:

表1(总分) overall

表2(每周得分) weekly

我有一个排行榜,我正在回应表1 的整体得分值

lb

问题:我在这里要做的是,无论谁得分" -10"在表2(每周得分)中,我想通过突出显示其排行榜中现在为黄色的方框颜色为红色来提醒用户。

当前的css涉及:



li mark div {
    display: block;
    margin: 4px;
    padding: 5px;
    min-height: 50px;
    border: 2px solid #eebb55;
    border-radius: 7pt;
    background: grey;
}




Php参与显示列表。这是为了"整体" (排行榜中的右侧标签)。每周也有相似的内容。



<div id="overalllb" class="leadboardcontent" style="display:none">
    <div class="leaderboard">
        <ol>
            <li>
                <mark>
                    <?php  while( $toprow2 = sqlsrv_fetch_array( $stmt3) ) {
                        echo  "<div class='parent-div'><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>
&#13;
&#13;
&#13;

传递查询以从两个表中检索信息:

1.query 1 - 查找得分为-10的所有员工。

&#13;
&#13;
$q200 = " select *
  from Table2
  where  WeekNumber = 'week1' and pointsRewarded = '-10';";
  $stmt200=sqlsrv_query($conn,$q200);
  if($stmt200==false)
  {
  echo 'error to retrieve info !! <br/>';
  die(print_r(sqlsrv_errors(),TRUE));
  }
&#13;
&#13;
&#13;

查询2-从表1中检索所有员工:

&#13;
&#13;
$q20 = "select *
  from EmployeeTable
  order by Total_points_Rewarded desc";
  $stmt20=sqlsrv_query($conn,$q20);
  if($stmt20==false)
  {
  echo 'error to retrieve info !! <br/>';
  die(print_r(sqlsrv_errors(),TRUE));
  }
&#13;
&#13;
&#13;

我正在使用PHP,请建议我这样做。上帝保佑。

3 个答案:

答案 0 :(得分:1)

通过在SQL语句中连接两个表,可以简化该过程。使用上面dhi_m中的代码,但数据将来自单个SQL查询:

myService.subscribe(
  result => {
     // your other stuff here.
     isLoading = false;
  },
  error => {
     isLoading = false;
  }

列表的HTML代码如下所示:

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

(未经测试,可能包含拼写错误)

答案 1 :(得分:0)

你可以签一个简单的php if..else来突出显示它..

假设您在内部用户循环使用$ usersscore

时存储用户的特定分数
if($usersscore<=-10){
    $highlightclass="redmark";
 }
else{
   $highlightclass-"yellowmark";
}

在HTML 中     在html元素的内部类中,您可以像

一样回应它
<li class="<?php echo $highlightclass; ?>">

答案 2 :(得分:0)

请试试这个

    <style>

    li mark div .parent-div-green {
        display: block;
        margin: 4px;
        padding: 5px;
        min-height: 50px;
        border: 2px solid #eebb55;
        border-radius: 7pt;
        background: grey;
    }

    li mark div .parent-div-red {
        display: block;
        margin: 4px;
        padding: 5px;
        min-height: 50px;
        border: 2px solid red;
        border-radius: 7pt;
        background: grey;
    }
</style>
<div id="overalllb" class="leadboardcontent" style="display:none">
    <div class="leaderboard">
        <ol>
            <li>
                <mark>
                    <?php  while( $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>