dougouqin0763 2016-12-07 22: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 08: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条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部