doutui839638 2016-05-16 11:58
浏览 27
已采纳

如何在PHP中对数据库创建的图表中的项目进行排序?

I have created a database which contains people from a run with the amount of rounds which they ran. After that I created this script which creates a html chart.

The script:

<?php
  $db = new PDO("mysql:host=HIDDEN;dbname=HIDDEN", 'HIDDEN', 'HIDDEN') or die ("Verbindung nicht möglich");
  $query_temp = $db->prepare("SELECT * FROM runners");
  $query_temp->bindParam(':id', $id);
  $id = 1;
  $query_temp->execute();

  echo '<table class="table table-hover">';
  echo '<tr>';
  echo '<th>ID</th>';
  echo '<th>Name</th>';
  echo '<th>Runden</th>';
  echo '</tr>';
  while($id_table = $query_temp->fetch(PDO::FETCH_ASSOC)) {
    echo '<tr>';
    echo '<td>'.$id_table['runner_id'].'</td>';
    echo '<td>'.$id_table['runner_name'].'</td>';
    echo '<td>'.$id_table['runner_rounds'].'</td>';
    echo '</tr>';
  }
  echo '</table>';
?>

The Database: http://img.prntscr.com/img?url=http://i.imgur.com/WklMcTG.png

Screenshot how it looks: http://img.prntscr.com/img?url=http://i.imgur.com/v2zbOSu.png

Now I want to give the users the ability to sort the people for their amount of rounds which they ran. Like the most person is at the first place. How can I do this?

  • 写回答

2条回答 默认 最新

  • douhuo3696 2016-05-16 12:05
    关注

    To make this you need a js plugin and turn the HTML dynamic. There is a lot of plugins to make it and will list some of them to you:

    1. datatables
    2. tablesorter

    Each plugin work differently, but in the end they have almost the same behaviour, then you need to check the documentation of them and try to run...

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

报告相同问题?

悬赏问题

  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗