根据另一个表中的条件在列表中突出显示一个框 [英] highlight a box in a list according to a condition in another table

查看:88
本文介绍了根据另一个表中的条件在列表中突出显示一个框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两张表:

表1(总分)



表2(每周得分)


我有一个排行榜,让我回应表1中的总得分值





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

涉及的当前css:

  li mark div {display:block; margin:4px;填充:5px;最小高度:50px; border:2px solid#eebb55;边界半径:7pt;背景:gray;}  



参与显示列表。用于整体(排行榜中的右侧标签)。每周也存在相似的情况。



 < div id =overalllbclass =leadboardcontentstyle =display:none> < div class =leaderboard> <醇> <李> <标记> <?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']。 < /跨度>< / DIV> 中; }?> < /标记> < /锂> < /醇> < / div>  



表:

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



$ q200 =select * from Table2 where WeekNumber ='week1'and pointsRewarded ='-10'; ; $ stmt200 = sqlsrv_query($康恩,$ Q200);如果($ stmt200 == false){回声'错误检索信息! <峰; br />;死亡(的print_r(sqlsrv_errors(),TRUE)); }

雇员:
$ b

$ q20 =select * from EmployeeTable按Total_points_Rewarded desc排序; $ stmt20 = sqlsrv_query($康恩,$ Q20);如果($ stmt20 == false){回声'检索信息的错误! <峰; br />;死亡(的print_r(sqlsrv_errors(),TRUE)); }



我使用PHP,请告诉我一种方法it.God祝福。

解决方案

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

  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

列表的HTML代码将如下所示:

 < div id =overalllbclass =leadboardcontentstyle =display:none> 
< div class =leaderboard>
< ol>
< li>
<标记>
<?php while($ toprow2 = sqlsrv_fetch_array($ stmt3)){
echo< div class ='。$ toprow2 ['display_status']。'>< span class = '秩' >中。 $ toprow2 ['overallRank']。 < / span>< span class ='name'> 。 $ toprow2 ['EmployeeName']。 < / span>< span class ='points'> 。 $ toprow2 ['Total_points_Rewarded']。 < /跨度>< / DIV> 中;
}
?>
< / mark>

< / li>
< / ol>
< / div>
< / div>

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


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 do here is that whoever scores "-10" in table 2 (weekly score) , I want to alert the user by highlighting the color of their box in the leaderboard ,which is yellow now, to red.

current css involved :

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

Php involved to display the list.This is for "overall" (right tab in leader board) .Similar exist for weekly too .

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

Queries passed to retrieve info from both the tables :

1.query 1 - to find out all the employees with a score of -10.

$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));
  }

query 2- to retrieve from table 1 all the employees :

$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));
  }

I am using PHP,Please suggest me a way to do it.God bless.

解决方案

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:

<div id="overalllb" class="leadboardcontent" style="display:none">
    <div class="leaderboard">
        <ol>
            <li>
                <mark>
                    <?php  while( $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)

这篇关于根据另一个表中的条件在列表中突出显示一个框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆