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 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化