2017-08-09 78 views
0

也许这个问题是如此基本,我无法找到它解释。从php获取%的百分比与php

我有一个2值的表。说明|从mysql中回荡的估值。 我正在寻求获取指示的百分比值(%)作为估值。 即10个约会/ 5个销售= 50%的转换率。 总和将销售/任命x 100 =%

任何想法如何将这个回声到我的html表''百分比'列?

$query = "SELECT * FROM office_figures2016"; 
$result = mysqli_query($conn, $query); 

while($office_figures2016=mysqli_fetch_assoc($result)){ 

echo "<tr>"; 
     //changes date to english format from a time stamp 
     echo"<td>".$office_figures2016['id_why']."</td>"; 

     echo"<td>".date('d-m-Y',strtotime($office_figures2016['date_figures']))."</td>"; 
     echo"<td>".$office_figures2016['valuations']."</td>"; 
     echo"<td>".$office_figures2016['instructions']."</td>"; 
     echo"<td>".$office_figures2016['percentage of above']."</td>"; 
+1

[MySQL Calculate Percentage]可能重复(https://stackoverflow.com/questions/15746749/mysql-calculate-percentage) – Sand

+0

你有你需要的一切,你知道计算是什么,那么究竟是什么问题 – RiggsFolly

+0

我想你要找的答案是[here](https:// stacko verfusion.com/questions/15746749/mysql-calculate-percentage) – Sand

回答

1
$query= "SELECT *, 
     concat(round((instructions/valuations * 100),2),'%') AS percentage 
    FROM office_figures2016"; 
    $result = mysqli_query($conn, $query); 
     while($office_figures2016=mysqli_fetch_assoc($result)){ 

     //echo "$applicant_card[id].$applicant_card[first_name]"; //this echos out a few columns = id and first_name 


     echo "<tr>"; 
     //changes date to english format from a time stamp 
     echo"<td>".$office_figures2016['id_why']."</td>"; 

     echo"<td>".date('d-m-Y',strtotime($office_figures2016['date_figures']))."</td>"; 
     echo"<td>".$office_figures2016['valuations']."</td>"; 
     echo"<td>".$office_figures2016['instructions']."</td>"; 
     echo"<td>".$office_figures2016['percentage']."</td>"; 
     echo"<td>".$office_figures2016['firsts']."</td>"; 


     echo "<td><a href='edit_figures.php?edit=$office_figures2016[id_why]'>Edit</a></td>"; 
     //echo "<td><a href='delete_applicant.php?id=$office_figures2016[id]'>x</a></td></tr>"; 

     } 
+0

标记此为该问题的最佳答案。 – Sand

+0

如果您不想将小数位数改为:100),2),'%')改为100),0),'%') – Glen

0

您不应该创建这样的列 - 在数据库中存在重复值是不好的习惯。这是简单的值,这样你就可以在每次计算的话,例如:

SELECT a.a, a.b, (a/b) FROM a ORDER BY (a/b); 

如果你真的想添加它,你可以简单地在phpMyAdmin创建列,然后更新它的宽度SQL

UPDATE A SET a_b=a/b 
+0

嗨,我的意思是一张桌子列中的HTML不在数据库埠感谢您的答案 – Glen