如何用php语言显示,最高值来自html内的列

8dtrkrch  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(316)

关闭。这个问题需要细节或清晰。它目前不接受答案。
**想改进这个问题吗?**通过编辑这个帖子来添加细节并澄清问题。

两年前关门了。
改进这个问题

<div class="col-sm-5 col-md-12 col-lg-6">
      <div class="panel panel-inverse">
        <div class="panel-heading">
          <h4 class="panel-title">TOP 5 BUNNY KILLERS</h4>
        </div>
        <div class="panel-body">
          <ul class="media-list user-list">
           <?php echo $output ?>
            <?php echo $output ?>
             <?php echo $output ?>
              <?php echo $output ?>
               <?php echo $output ?>
          </ul>
        </div>
      </div>
    </div>

$sql = "SELECT Username, BunnyKilled FROM users order by BunnyKilled DESC LIMIT 5;";
$con=mysqli_connect("yes","yes","yes","yes");
$results =  array();
$result = mysqli_query($con,$sql);
$results = mysqli_fetch_all($result, MYSQLI_ASSOC);

$output = '';

foreach ($results as $result) {
$output = '  <li class="media"> <div class="media-left"> <a href="#">  <img class="media-object img-circle" src="../images/photos/user9.png" alt=""> </a> </div> <div class="media-body"> <h4 class="media-heading"><a href="">'. $result['Username'] . '</a></h4> <span>' . $result['BunnyKilled'] . '</span> bunny killed</div> </li>' ;
    }

我也在用

if(isset($_SESSION['username']))

显示兔子杀手的个人信息,但我想显示的前5名兔子杀手,按他们的兔子被杀的数量排序的每个杀手。在它不起作用之后,我把var转储,这就是我得到的

array(5) {
  [0]=>
  array(2) {
    ["Username"]=>
    string(19) "Abdulhamit_Yildirim"
    ["BunnyKilled"]=>
    string(2) "15"
  }
  [1]=>
  array(2) {
    ["Username"]=>
    string(4) "Ampo"
    ["BunnyKilled"]=>
    string(1) "5"
  }
  [2]=>
  array(2) {
    ["Username"]=>
    string(15) "Timothy_Bronson"
    ["BunnyKilled"]=>
    string(1) "5"
  }
  [3]=>
  array(2) {
    ["Username"]=>
    string(6) "Rvmses"
    ["BunnyKilled"]=>
    string(1) "4"
  }
  [4]=>
  array(2) {
    ["Username"]=>
    string(3) "Esy"
    ["BunnyKilled"]=>
    string(1) "3"
  }
}

刚刚更新了var\u dump结果,我把它放在了fetch之后

kcugc4gi

kcugc4gi1#

您的mysql查询应该如下所示:
按BunnyDesc limit 5从looneytunes订单中选择*;
前5名按顺序排列,限制5名。
您的php应该类似于:

<?php 
            $sql = "SELECT Username, BunnyKilled FROM users order by BunnyKilled DESC LIMIT 5;";

            $results =  array();
            $result = mysqli_query($con,$sql);

            $results = mysqli_fetch_all($result, MYSQLI_ASSOC);

        $output = '';

            foreach ($results as $row) {

        $output .= '  <li class="media"> <div class="media-left"> <a href="#">  <img class="media-object img-circle" src="../images/photos/user9.png" alt=""> </a> </div> <div class="media-body"> <h4 class="media-heading"><a href="">'. $row['Username'] . '</a></h4> <span>' . $row['BunnyKilled'] . '</span> bunnies killed</div> </li>' ;
            }

        echo $output;

?>

相关问题