也许这个问题太基本了,我找不到它的解释。
我有一个包含 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>";
最佳答案
$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>";
}
关于php - 使用 php 从 mysql 获取 % 百分比,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45587577/