也许这个问题是如此基本我无法解释它。
我有一个包含2个值的表。说明|来自mysql的估值。 我希望得到指令的%(百分比)值到估值。 即10个预约/ 5个销售= 50%的转换率。 总和将是Sales / Appoints 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>";
答案 0 :(得分: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>";
}
答案 1 :(得分:0)
您不应该创建这样的列 - 在数据库中使用重复值是不好的习惯。它是简单的值,因此您可以每次计算它,例如:
SELECT a.a, a.b, (a/b) FROM a ORDER BY (a/b);
如果你真的想添加它,你可以简单地在phpMyAdmin中创建列然后更新它的宽度sql
UPDATE A SET a_b=a/b