2017-08-09 267 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