dougouqin0763 2016-12-08 06:45
浏览 32
已采纳

仅使用1个查询在排行榜中回显toppers

I have used the below php code to retrieve the top 8 from an EmployeeTable (connection part I havenot included below as it is irrelevant ) :

$q4 = "select top 8 *
from EmployeeTable
order by LevelFieldTotal desc";

$stmt3=sqlsrv_query($conn,$q4);
if($stmt3==false)
{
echo 'error to retrieve info !! <br/>';
die(print_r(sqlsrv_errors(),TRUE));
}
$toprow2=sqlsrv_fetch_array($stmt3);

I want to echo the top 8 in this leaderboard : https://jsfiddle.net/o20n61eu/4/

I tried to echo it in the html ,but I am getting only the ist person among the toppers getting echoed.

How Can I echo in the leaderboard,such that I get to see all the top 8 persons in the leaderboard through the above php variable,which holds the top8 in it.

I donot want to do it individually for each person.I want to use the above query and fetch the top8 through only one query and echo it.

the part of the html,where I tried to echo the php variable :(its in the above fiddele link also)

<div id="overalllb" class="leadboardcontent" style="display:none">
  <div class="leaderboard">

    <ol>
      <li>
        <mark>
          <?php echo "". $toprow2[ 'EmployeeName'] . ""?>
        </mark>
        <small><?php echo "". $toprow2['Total_points_Rewarded'] .""?></small>
      </li>
      <li>
        <mark>Brandon Barnes1</mark>
        <small>3101</small>
      </li>
      <li>
        <mark>Raymond Knight1</mark>
        <small>2192</small>
      </li>
      <li>
        <mark>Trevor McCormick1</mark>
        <small>2145</small>
      </li>
      <li>
        <mark>Andrew Fox1</mark>
        <small>2103</small>
      </li>
      <li>
        <mark>And1rew Fox1</mark>
        <small>2103</small>
      </li>
      <li>
        <mark>Tre1vor McCormick1</mark>
        <small>2145</small>
      </li>
      <li>
        <mark>Andrew Fox1</mark>
        <small>2103</small>
      </li>

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

solution as suggested by @Magnus and @Mayank

<div id="overalllb" class="leadboardcontent" style="display:none">
  <div class="leaderboard">

    <ol>
      <li>

        <mark>
          <?php while( $toprow2=s qlsrv_fetch_array( $stmt3) ) { echo $toprow2[ 'overallRank'] . "&nbsp;&nbsp;&nbsp;".$toprow2[ 'EmployeeName'] . "&nbsp;&nbsp;&nbsp;".$toprow2[ 'Total_points_Rewarded']. "<br/>";} ?>
        </mark>

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

Kindly help.Thanks.God bless.

</div>
  • 写回答

2条回答 默认 最新

  • donjd86266 2017-01-09 16:41
    关注

    use this :

    function myFunction() {
        var input, filter, ol, li, a, i;
        input = document.getElementById("search52");
        filter = input.value.toUpperCase();
        ol = document.getElementById("myOL");
        li = ol.getElementsByTagName("li");
        divs=li[0].getElementsByClassName("parent-div");
        for (i = 0; i < divs.length; i++) {
            a = divs[i].getElementsByClassName("name")[0];
            if (a.innerHTML.toUpperCase().indexOf(filter) > -1) {
                divs[i].style.display = "";
            } else {
                divs[i].style.display = "none";
            }
        }
    }

    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测