php - 创建水平条形图

标签 php mysql

我想使用 php、mysql、javascript、css、html 和“wamp 服务器”在网页中制作水平条形图,编辑器:“Macromedia Dreamweaver”,浏览器:“Mozilla Firefox”;

<小时/>

我想从表格中读取数据(学期结果),并通过条形图显示数据,例如, enter image description here

<小时/>
  • 数据库名称 考试

  • 表名称 'sem_result' 包含以下列>> regno[主键], uid, reg_date, exam_date, sem, result;

<小时/>

php 代码是::

<?php
// Connect to server
$cn=mysql_connect("localhost", "root", "");
//Connect to Database
mysql_select_db("exam") or die(mysql_error());
//sql query
$sql="SELECT result FROM sem_result WHERE uid=11111";
//collect results
$result=mysql_query($sql,$cn);
//read data if found
$counter=0;
while($rd=mysql_fetch_array($result))
{
 $sem_result[$counter]=$rd[0]; //save sem results into array
 $counter=$counter+1;
}
//display
echo "<table>
<tr>
    <td>sem1</td>
    <td width='100px'>
      <img src='img/menu_back.png' width='".$sem_result[0]."%' height='15px'/>
    </td>
    <td>".$sem_result[0]."%</td>
</tr>
<tr>
    <td>sem2</td>
    <td width='100px'>
      <img src='img/menu_back.png' width='".$sem_result[1]."%' height='15px'/>
    </td>
     <td>".$sem_result[1]."</td>
</tr>
</table>";
//close database
mysql_close($cn);
 ?>
<小时/>

如果结果是 78.95%,78.10%,条形图显示两个结果相等,即 78%;
图片宽度变成78%,不是78.95%,请帮忙解决这个问题。

最佳答案

更改表名和列名以及progress.png图像。 之后使用它。

`

<?php $s="select count(*) as tnum from leakage";
$r=mysql_query($s) or die (mysql_error());
while($rw=mysql_fetch_array($r))
{
echo $tno=$rw['tnum'];
}
?>

<table class="table table-hover">
<thead>
<tr>
 <th>DEPARTMENT</th>
 <th>No.Of Leakage</th>
</tr>
</thead>
<?php 
  $sql1="select dept,count(dept) as total from leakage where dept='winding'";
 $result1=mysql_query($sql1) or die(mysql_error());
 while($row=mysql_fetch_array($result1))
 {

 $dept=$row['dept'];
  $tot=$row['total'];
 }                                  
 ?>
 <tr>
 <td><?php echo $dept; ?></td>
 <td width="100%"><img src="assets/images/progress.png" width="<?php   echo (($tot/$tno)*100);?>" height="20px"><?php echo $tot;?>%</td>

 </tr>

 <?php 
   $sql2="select dept,count(dept) as total from leakage where dept='spining'";
   $result2=mysql_query($sql2) or die(mysql_error());
   while($row=mysql_fetch_array($result2))
   {

  $dept=$row['dept'];
 $tot=$row['total'];
  }     
  ?>
   <tr>
 <td><?php echo $dept; ?></td>
  <td width="100%"><img src="assets/images/progress.png" width="<?php echo (($tot/$tno)*100);?>" height="20px"><?php echo $tot;?>%</td>

    </tr>
   <?php 
    $sql5="select count(dept) as total from leakage";
    $result5=mysql_query($sql5) or die(mysql_error());
    while($row=mysql_fetch_array($result5))
   {

     $tot=$row['total'];
   }        
   ?>
   <tr>
   <td>Total</td>
       <td width="100%"><img src="assets/images/progress.png" width="<?php echo $tot;?>" height="20px"><?php echo $tot; ?></td>
     </tr>
      </table>

`

关于php - 创建水平条形图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23453190/

相关文章:

java - 如何使用JPA、Hibernate、Spring Boot实现复合主键和复合外键

mysql - ruby检查数据库中是否存在数据

php - 在执行函数之前检查sql中的日期时间

php - 如果 $_SERVER ['HTTP_REFERER' ] 不可靠,我将使用什么来确保网络应用程序的完整性?

php - 使用 PHP 正则表达式匹配字符串中的任何 Unicode 空白字符

php - 如何在 PHP 中转义#

sql - 当第二个表可能没有相关行时如何限制联接

php - 如何从同一文件夹中的外部文件中回显 html 片段?

php - Codeigniter:如何检查mysql数据库中的用户名是否已存在

mysql - django sql explorer - 基于用户的查询访问