php - 使用 php 从 mysql 获取 % 百分比

标签 php mysql

也许这个问题太基本了,我找不到它的解释。

我有一个包含 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/

相关文章:

mysql - 无法再次连接到 AWS RDS

mysql - 我还可以使用这个多对多连接表执行哪些其他查询?

php - 网站。 AJAX 和 FIREFOX 问题。我认为 Firefox 不喜欢 ajax..?

php - 如何在 Yii 中设置默认 Controller

php - Symfony2 - 要查看 Twig 中的更改,每次都必须清除缓存

php - 使用PHP上传文件并添加到MySQL数据库的路径

mysql "IN"条件与子查询

mysql - 比较sql中的两个值

PHP - 将选择选项值发布到index.php添加用户

php - Facebook PHP SDK 抛出无法捕获的 "GraphMethodException"错误