我试图创建一个简单的条形图来显示一个体育赛事(例如100米比赛)的结果,我已经生成了一个'结果'表这个事件的结果显示-但我希望该网站的用户能够点击一个'视图图'类型按钮,将显示这些结果在一个(水平)条形图。
最容易/最简单的方法是什么?
以下是我已经在我的'viewesults3.php'页面上的内容: <?php
session_start();
require_once("connect.php");
//require_once("restriction.php");
?>
<html>
<body>
<div id="mainFrame">
<form id="results" method="get">
<table id="results" border="1" bordercolor="#FFCC66">
<th bgcolor="#FFCC66">Result ID: </th>
<th bgcolor="#FFCC66">Position: </th>
<th bgcolor="#FFCC66">Time: </th>
<th bgcolor="#FFCC66">Event ID: </th>
<th bgcolor="#FFCC66">Athlete ID: </th>
<?php
$result = mysql_query("SELECT * FROM Results");
while ($row = mysql_fetch_array($result))
{
$rID = $row['rID'];
$position = $row['position'];
$time = $row['time'];
$meID = $row['meID'];
$atID = $row['atID'];
echo "<tr data-row='$rID'><td>$rID</td>";
echo "<td>".$position."</td>";
echo "<td>".$time."</td>";
echo "<td>".$meID."</td>";
echo "<td>".$atID."</td>";
echo "</tr>";
}
?>
</table>
</form>
</div>
<center>
<div id="graphs" align="center">
<a href=".php" class="button">Generate graph!</a>
</div>
</center>
</body>
</html>
使用纯sql的一个简单方法是mysql的REPEAT函数。无论结果值是多少,您都可以重复一个字符X次(四舍五入或截断以删除分数)。
下面是一个例子:
http://sqlfiddle.com/!2/0e2d7/1/0
在该示例中,我根据"score"值(根据需要进行调整)重复管道字符(|)x次。
还可以突出显示HTML中的管道字符,使每个管道字符成为实条。