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 C语言设计一个简单的自动换档程序
  • ¥15 关于logstash转发日志时发生的部分内容丢失问题
  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。